Hello,
I've an app where users submit some info about their profile and save.
I need to place on save button an if condition to differentiate the patch command, because first-time people will save their profile the patch will create a new item on a sharepoint list, but then if the user wants to edit some field and save again the patch will update.
Patch to create a new item:
Patch(Users, Defaults(Users),
{ Name:
{
'@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
Claims:"i:0#.f|membership|" & Lower(User().Email),
Department:"",
DisplayName:User().FullName,
Email:User().Email,
JobTitle:".",
Picture:User().Image
},
InternalNumber:Value(txtNInterno.Text),
PhoneNumber:Value(txtContacto.Text),
CostCenter:Value(txtCC.Text),
Company:drpEmpresa.SelectedText,
Manager:cmbChefia});
UpdateContext({varViewMode:true})
Patch to edit existing item based on if the user already exists on the list:
Patch(Users, LookUp(Users,Name.DisplayName = User().FullName), {
InternalNumber:Value(txtNInterno.Text),
PhoneNumber:Value(txtContacto.Text),
CostCenter:Value(txtCC.Text),
Company:drpEmpresa.SelectedText,
Manager:cmbChefia})
___
I've tried this on two different buttons and it worked, now I Need to join both on save button with the following logic:
If the User().Fullname already exists on sharepoint list, field name perform patch to create, otherwise patch to edit.
Someone can help me?
Hi @Miguel_MESP,
Try to adapt this to your needs:
Patch( my_data_source,
Coalesce (
LookUp( my_data_source, condition),
Defaults( my_data_source)
),
{….values to create/update ….}
)
The coalesce part because there is our problem checks if there are any records and if found one use it else use Defaults() function.
Hope it helps !
it's not working, it doesn't perform any action
Sure! Thanks for the help!
Patch(Users, Coalesce(LookUp(Users,Name.DisplayName = User().FullName), Defaults(Users)),
{ Name:
{
'@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
Claims:"i:0#.f|membership|" & Lower(User().Email),
Department:"",
DisplayName:User().FullName,
Email:User().Email,
JobTitle:".",
Picture:User().Image
},
InternalNumber:Value(txtNInterno.Text),
PhoneNumber:Value(txtContacto.Text),
CostCenter:Value(txtCC.Text),
Company:drpEmpresa.SelectedText,
Manager:cmbChefia});
Stay up tp date on the latest blogs and activities in the community News & Announcements.
Mark your calendars and join us for the next Power Apps Community Call on January 20th, 8a PST
Dive into the Power Platform stack with hands-on sessions and labs, virtually delivered to you by experts and community leaders.
User | Count |
---|---|
212 | |
194 | |
82 | |
59 | |
38 |
User | Count |
---|---|
305 | |
255 | |
120 | |
86 | |
55 |