Update the support account from the due date to the invoice

In this example we see how to update the support account present on the invoice from the deadline.

Script GroupEvent
FormPost saving
gguidp = dataview.getvalue("gguidp")
tap    = dataview.getvalue("tap")
 
if gguidp == "" or tap == "" then
        do return end
end

First let's see if the deadline actually hase a father record by checking the gguid and tap field, since the whole program links the records using these two values.

The gguid value identifies the father row, while tap value identifies the father table. If these fields have no values, then the deadline was created by the user, otherwise it was another table that created it.

gguidc = dataview.getvalue("gguid_supportaccount")
if gguidc == "" then
        do return end
end

We also recover the support account gguid. Again if you don't have a value, then we exit the script.

tablebill = database.getsql("SELECT * FROM companyaccounts WHERE gguid='" .. gguidc .. "'")
 
if tablebill.countrows() == 0 then
        do return end
end
rows = tablebill.getrows()


output.print(rows[1].getvalue("billname"))
output.print(righe[1].getvalue("bankaccount"))
output.print(righe[1].getvalue("iban"))

We recover the bank account values from its gguid. These values will be those that we will write on the invoice.

database.setsql("UPDATE " .. tap .. " SET TID=" .. tostring(utility.tid()) .. ",supportaccount='" .. utility.convap(rows[1].getvalue("billname")) .. "',currentaccountfirm='" .. utility.convap(rows[1].getvalue("bankaccount")) .. "',ibanfirm='" .. utility.convap(rows[1].getvalue("iban")) .. "' WHERE gguid='" .. gguidp .. "'")

database.addsyncbox(tap,gguidp)
program.refreshsection("invoices"

Lastly, we update the invoice connected with the conto data. If the database is Cloud type, it will be necessary to remember to always update the tid (the date and time of modification of the record) and to add it to the syncbox.

Modified the data, we force the updating of the sections that recall the invoices table.