I am to create an address collection form for my work team. How do I make it so that when someone on my team submits their data it will create a new entry and if it there is an existing entry, then it will update the previous entry?
I like to make it so that the work "alias" box is used a reference to determine if there is an existing entry.
Currently, my formula to create new entries is:
Patch(
'Shipping Form',
Defaults('Shipping Form'),
{
'First Name': firstnameinput.Text,
'Last Name':lastnameinput.Text,
'Alias':aliasinput.Text,
'Address Line 1':addressline1input.Text,
'Address Line 2':addressline2input.Text,
'State/Province':stateinput.Text,
'Zip/Postal Code':zipinput.Text,
'City/Region':cityinput.Text,
'Permission to share to Reporting Manger if needed?':'Perminput',
'Country': CountryData,
'Contact Name': Contactnumberinput.Text,
'Comments:':commentinput.Text
}
)
;ResetForm(Form2)
How do I add onto the formula for it to also check for existing entries based on "alias" and update if there is a duplicate "alias" value?
Thank you,
The second argument to the Patch function is the record to be updated; if you use Defaults(...), then a new record is created. So you can use something like this to update a record if it exists, or create otherwise:
With(
{
recordToUpdate:
Coalesce(
LookUp('Shipping Form', Alias = aliasinput.Text),
Defaults('Shipping Form')
)
},
Patch(
'Shipping Form',
recordToUpdate,
{
'First Name': firstnameinput.Text,
'Last Name':lastnameinput.Text,
'Alias':aliasinput.Text,
'Address Line 1':addressline1input.Text,
'Address Line 2':addressline2input.Text,
'State/Province':stateinput.Text,
'Zip/Postal Code':zipinput.Text,
'City/Region':cityinput.Text,
'Permission to share to Reporting Manger if needed?':'Perminput',
'Country': CountryData,
'Contact Name': Contactnumberinput.Text,
'Comments:':commentinput.Text
}
)
)
;ResetForm(Form2)