I'm trying to patch a data source based on values in a collection and cannot figure out how to do it.
Here's my situation. I have a web site that has 10 pages on it. Each page has a message box where I want to post messages to. The web site is database driven and I have a table for the page information.
The table (dbo.Pages) has ID (primary key), Title, and AlertHtml columns.
My PowerApp has dbo.Pages as a data source.
I have a text box for a message, a list box for pages, and I have a gallery for styles (which gets prepended to the text box value)
I want to be able to post the message to any pages I select in the list box.
My initial thought was to put the Pages selected from the list box into a collection (colChosenPages) then loop through them and patch to dbo.Pages. But there is NO LOOP function! I looked at ForAll and Patch combinations but I don't understand how I use the matching criteria in Patch.
Here's what I was trying that does not work.
ForAll(colChosenPages,Patch('[dbo].[Pages]',Id=colChosenPages.Id,{AlertHtml:varMessageText})))
How can I add the message to the pages table for each of the pages chosen in the list box?
Thank you
Solved! Go to Solution.
Hi @Capt_Ron ,
Do you want to modify several records at the same time?
I've made a similar test for your reference:
Set the listbox's OnChange:
ClearCollect(selecteditems,Filter('[dbo].[Pages]',ID in ListBox1.SelectedItems.ID))
Set the button's OnSelect:
ForAll(selecteditems,Patch('[dbo].[Pages]',LookUp('[dbo].[Pages]', ID = selecteditems[@ID]),{AlertHtml:varMessageText}))
Here's a doc about update multiple records for your reference:
https://powerapps.microsoft.com/en-us/blog/bulk-update-using-forall-and-patch/
Best regards,
Community Support Team _ Phoebe Liu
Hey!
Please refer to the screenshot below:
Thank you.
So, I'm trying to do the same this you have in your response except I need to update the records.
In my case the gallery is actually irrelevant. I just grab an attribute from the selected item and concatenate it in front of the text box Text value. UpdateContext({varMessageText:Concatenate(Gallery1.Selected.Title,Textbox1.Text})
For simplicity, I want to:
ForAll(Listbox1.SelectedItems,Patch('[dbo].[Pages]',***This is where I don't know what to do***,{AlertHtml:varMessageText})))
Hope this helps
Ron
Hi,
ForAll(Listbox1.SelectedItems,Patch('[dbo].[Pages]',Lookup('[dbo].[Pages]', <<condition>>),{AlertHtml:varMessageText})))
Hi @Capt_Ron ,
Do you want to modify several records at the same time?
I've made a similar test for your reference:
Set the listbox's OnChange:
ClearCollect(selecteditems,Filter('[dbo].[Pages]',ID in ListBox1.SelectedItems.ID))
Set the button's OnSelect:
ForAll(selecteditems,Patch('[dbo].[Pages]',LookUp('[dbo].[Pages]', ID = selecteditems[@ID]),{AlertHtml:varMessageText}))
Here's a doc about update multiple records for your reference:
https://powerapps.microsoft.com/en-us/blog/bulk-update-using-forall-and-patch/
Best regards,
Community Support Team _ Phoebe Liu
For closure, I wanted to post my final code (test code) that works.
This is on the Save Button:
ClearCollect(SelectedPages,ListBox1.SelectedItems); ForAll(SelectedPages,Patch('[dbo].[SSOPagesTest]',LookUp('[dbo].[SSOPagesTest]',pk_ID=SelectedPages[@pk_ID]),{HTMLAlert:Concatenate("Testing<|>",TextInput1.Text)})); Refresh('[dbo].[SSOPagesTest]')
The key is the SelectedPages[@pk_ID] piece.
@v-yutliu-msft Thank you very much.
User | Count |
---|---|
139 | |
132 | |
75 | |
72 | |
68 |
User | Count |
---|---|
214 | |
199 | |
64 | |
62 | |
54 |