cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
calvares
Kudo Kingpin
Kudo Kingpin

Updating records - ForAll, UpdateIf and/or Update?

So I'm trying to work out how to update a contact name and phone number in my SP data source ('Emergency contacts').

There are 4 contacts in the data source which are all people pickers: LabContact1, LabContact2, DeptContact1, DeptContact2.

There is a phone number field for each of these contacts: LabNumber1, LabNumber2 etc.

I have a screen which enables the user to search for all records with their selected contact and there will be an option to update them with a new contact name and phone number.

Screenshot 2021-11-16 122445.png

 

To make it easier for the user, they don't have to know whether the contact they're looking for is LabContact1, 2 etc. I created a collection (colAllContacts) on visible of the screen which adds LabContact1 and LabContact2 into one column called 'LabContacts', DeptContact1 and 2 are in the column 'DeptContacts'. Then I have the same for the phone numbers. 

 

The user only has to select whether the contact they want to update is a lab contact or a department contact. Then there is a combobox for lab and one for department which is visible depending on the value of the radio button. 

 

The gallery filters on a collection colEC which is data from Emergency Contacts.

 

To determine whether the selected contact is in LabContact 1 or 2 or DeptContact 1 or 2 I also added a LabRef and DeptRef column to colAllContacts. Then I have a label called LabelLabRefLookUp which looks up what the LabRef should be for the selected contact and another called LabelDeptRefLookUp which does the same for the dept ref.

 

So this is where I get stuck. Potentially I could start with a condition like this to update any LabContacts1

If(Radio2.Selected.Value = "Lab" && LabelLabRefLookUp.Text = "1",

Then do I need a ForAll statement to iterate through all the records or is it sufficient that my filtered gallery has the records needed for update? Could I do this with an Update statement or would UpdateIf be better?

 

The replacement contact field is called ComboBoxNewContact and linked to Office365Users. The phone number text input is called TextInputNewNumber.

1 ACCEPTED SOLUTION

Accepted Solutions
sgtsnacks
Helper I
Helper I

Hi Calvares,

 

I think I understand your problem correctly, apologies if I've misunderstood the requirements here.

 

You can reference the filtered items in a gallery using the Gallery.AllItems property. You can then use a ForAll statement with Patch to update the SP Records (Update runs on the entire record, UpdateIf should be okay to specify columns, Patch will target specific columns).

 

sgtsnacks_0-1637075663456.pngAll Values showing as "Whiff"

 

sgtsnacks_1-1637075696876.pngGallery filtered to "123456451"

sgtsnacks_2-1637075732529.pngPatched Gallery.AllItems with "Whaff"

 

sgtsnacks_3-1637075773182.pngUnfiltered Gallery to show only 123456451 updated to Whaff, all other records remain as "Whiff"

 

Something like this I believe should work:

ForAll(Gallery.AllItems,Patch('SP Data Source',{ID: ID},{'SP ColumnName':"New Value",'SP ColumnName2':"New Value 2"}))

This will only affect the filtered records at the point of executing the command.

 

For performance, it would be worth doing any calculcations outside of the ForAll statement were possible (Where you may conditionally populate a column based on a radio button being toggled), as the calculation will occur each record and will affect performance on larger lists when executed within the ForAll Statement.

 

 

View solution in original post

2 REPLIES 2
sgtsnacks
Helper I
Helper I

Hi Calvares,

 

I think I understand your problem correctly, apologies if I've misunderstood the requirements here.

 

You can reference the filtered items in a gallery using the Gallery.AllItems property. You can then use a ForAll statement with Patch to update the SP Records (Update runs on the entire record, UpdateIf should be okay to specify columns, Patch will target specific columns).

 

sgtsnacks_0-1637075663456.pngAll Values showing as "Whiff"

 

sgtsnacks_1-1637075696876.pngGallery filtered to "123456451"

sgtsnacks_2-1637075732529.pngPatched Gallery.AllItems with "Whaff"

 

sgtsnacks_3-1637075773182.pngUnfiltered Gallery to show only 123456451 updated to Whaff, all other records remain as "Whiff"

 

Something like this I believe should work:

ForAll(Gallery.AllItems,Patch('SP Data Source',{ID: ID},{'SP ColumnName':"New Value",'SP ColumnName2':"New Value 2"}))

This will only affect the filtered records at the point of executing the command.

 

For performance, it would be worth doing any calculcations outside of the ForAll statement were possible (Where you may conditionally populate a column based on a radio button being toggled), as the calculation will occur each record and will affect performance on larger lists when executed within the ForAll Statement.

 

 

View solution in original post

calvares
Kudo Kingpin
Kudo Kingpin

Brilliant, thank you @sgtsnacks. I had to use an @odata reference for the people field update but that works really well.

I've also updated the gallery to filter on the actual data source rather than collection so the updates can be seen.

I need to do some more work on the conditions but thanks for the tip on doing it outside of the the ForAll statement.

Helpful resources

Announcements
2022 Release Wave 1 760x460.png

2022 Release Wave 1 Plan

Power Platform release plan for the 2022 release wave 1 describes all new features releasing from April 2022 through September 2022.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Top Solution Authors
Top Kudoed Authors
Users online (2,157)