cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
rolivier
Helper I
Helper I

ForAll Patch Problem

I've been struggling with this for days.   Hoping someone can help me ("Please" and "Thank You" in advance). 

 

I have a:

- SQL Server Table named "DailyPaperwork".
- Powerapp Collection named "DailyPaperworkCollection".

Users work offline and new entries can be added to the SQL-Table or the Collection by various users.   So I can't "ClearCollect" the collection because it will overwrite any new entries that they've put in the collection.    

End goal is basically to sync the tables.   (I need to get a SQL-autogenerated ID field to the tablets for another function).  

 

I'm trying to do something like the code below.   

ForAll(Filter(DailyPaperworkCollection,IsBlank(ID)),
Patch('[dbo].[DailyPaperwork]',Defaults('[dbo].[DailyPaperwork]'));
Patch(DailyPaperworkCollection, ThisRecord);
);

In words:
For all in my collection that were made on the tablet (because they have no SQL generated ID), 
Send to SQL. 
Then Send them back to the tablet (with their ID).   

 

I've tried various nested Patch/Update/ForAll statements, but can't seem to get this to work.   

 

Thanks again!

3 REPLIES 3
yashag2255
Dual Super User II
Dual Super User II

@rolivier 

 

The Patch expression requires three arguments, datasource, record to Update and then updates to the selected row.

You can get more info here: https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-patch

 

If you can share more details about the logic and the schema of the datasource, we might be able to help you with the expressions.

 

 

Hope this Helps!

 

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

Thanks...  

 

To clarify:   I'm not having a problem with the patch function.   The problem I'm having is telling the last patch which record to update.   

The ForAll and first patch work fine.    
The 2nd Patch doesn't work - I'm assuming because it can't identify the "ThisRecord" from within the "ForAll"? But I don't know how else to identify the record.   

yashag2255
Dual Super User II
Dual Super User II

@rolivier 

 

I tried to configure this myself, and with "This Record", I am able to identify the row in collection. 

Expression Used: ClearCollect(abc,{Name:"AC",Value:1},{Name:"",Value:1}); ForAll(Filter(abc,IsBlank(Name)), Patch(abc,ThisRecord, {Value:3}))

 

You can also try: 

ClearCollect(abc,{Name:"AC",Value:1},{Name:"",Value:1}); ForAll(Filter(abc,IsBlank(Name)), Update(abc,ThisRecord, {Value:3}))

 

Can you try the name in your case? 

 

 

Hope this Helps!

 

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on June 15, 2022 at 8am PDT.

PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Top Solution Authors
Top Kudoed Authors
Users online (1,918)