if else statement to update existing records or create new one
I am trying to transfer records from Form1 to Form2 on creation and edit. Both forms have the same look up field based on a third form. Creating the record works fine. For editing, there could be multiple entries with the same lookup field value, so I am checking for records with lookupfield ID and matching request date. The script doesn't work, but I'm not sure why. It just always creates a new record.
See my script below.
-----
record = Form2[ID == input.LookupField && Request_Date == input.Request_Date];
if(record.count() > 0)
{
record.Amount_Requested=input.Amount_Requested;
record.Request_For=input.Request_For;
record.Requested_By=input.Requested_By;
record.Notes_for_requester=input.Notes_for_requester;
}
else
{
insert into Form2
[
LookupField=input.LookupField
Request_Date=input.Request_Date
Amount_Requested=input.Amount_Requested;
Request_For=input.Request_For;
Requested_By=input.Requested_By;
Notes_for_requester=input.Notes_for_requester;
]
}