web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / How to patch a collect...
Power Apps
Answered

How to patch a collection back to table/entity

(0) ShareShare
ReportReport
Posted on by 17

Hi there,

 

I've created a collection from a gallery with 2 columns: API number and Well Name. I've built out my app using just the API name from the collection as the primary name column in my table. I'd like to now add the Well Name column from the collection to my table as well, but am having trouble doing so.

 

The script to grab the data from the gallery:

Collect(SelectedWellsZ,{
selAPI:ThisItem.'API Number',
wellName:ThisItem.'Permitted Legal Well Name'})

 

The script I wrote attempting to now patch the Well Name back to my table as a column labeled Permitted Well Name:

ForAll(SelectedWellsZ, Patch('Mudlogging Performance',
If(CountRows(Filter('Mudlogging Performance',API=selAPI))>0,LookUp('Mudlogging Performance',API=selAPI),Defaults('Mudlogging Performance'))
,{
API:selAPI,
'Permitted Well Name':wellName
}
));
Navigate(PerfReview_2)

 

The script does not have any errors, but it does not write Well Name back to my table as Permitted Well Name. What am I missing??

 

Thank you! Appreciate any and all insight.

 

Kate

Collection screenshot.png
Gallery collection script.png
Patch script.png
Categories:
I have the same question (0)
  • WarrenBelz Profile Picture
    154,924 Most Valuable Professional on at

    Hi @Schwehr07 ,

    You may have to do something different - conditional parameters around the Patch type may require a bit of the "long way" as below

    ForAll(
     SelectedWellsZ, 
     If(
     IsBlank(
     LookUp(
     'Mudlogging Performance',
     API=selAPI
     ).API
     ),
     Patch(		 
     'Mudlogging Performance',
     Defaults('Mudlogging Performance'),
     {
     API:selAPI,
     'Permitted Well Name':wellName
     }
     ),
     Patch(		 
     'Mudlogging Performance',
     {API:selAPI},
     {'Permitted Well Name':wellName}
     )
     )
    );
    Navigate(PerfReview_2)

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

  • Schwehr07 Profile Picture
    17 on at

    Hi @WarrenBelz 

     

    Thank you for the response! However, there are errors and I've attempted to track them but can't quite figure out where it went wrong. I think that the .API in line 65 highlighted below in red is an error, and from there Power Apps is saying the if statement has an error as does one of the patch statements. Reading the script through and comparing to mine, I'm confused by the IsBlank statement- in my CountRows >0 statement I'm specifying that there are new wells to add to the database, the IsBlank statement seems to be doing the opposite and specifying that the mudlogging performance table is only patched when there are no new wells in the SelectedWellsZ collection. However I am definitely a coding newbie and could absolutely be reading this wrong. Just trying to figure out why this code doesn't work. I am also confused by the two patch statements- is the first one defaulting to the original mudlogging performance table and the second one changing the mudlogging performance table based on the API values? (or maybe the second one is patching the Permitted well name column into the API column?) Again, thank you for your help! I'm trying to figure out why your statement doesn't work and what it's trying to do.

    Schwehr07_0-1618882803111.png

    Cheers,

     

    Kate

  • Verified answer
    WarrenBelz Profile Picture
    154,924 Most Valuable Professional on at

    Hi @Schwehr07 ,

    I have just noticed, you have an extra comma after the second last } bracket.
    I will also set out the logic below. I have tested the syntax here on a list and a collection, got no errors and it worked perfectly, however I use SharePoint

    ForAll(
     SelectedWellsZ, // loop through all the collection
     If(
     IsBlank(
     LookUp(
     'Mudlogging Performance',
     API=selAPI
     ).API //See if a record exists in the list where the API in the
     //collection equals the Variable selAPI
     ),
     Patch(	 //if a record DOES NOT exist, create a new one
     'Mudlogging Performance',
     Defaults('Mudlogging Performance'),
     {
     API:selAPI,
     'Permitted Well Name':wellName
     }
     ),
     Patch(		 //if a record exists, update that record
     'Mudlogging Performance',
     {API:selAPI},
     {'Permitted Well Name':wellName}
     )
     )
    );
    Navigate(PerfReview_2)

    I do not know what selAPI is  - it has to be of the same field type as API is in your list - maybe that is the issue.

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

  • WarrenBelz Profile Picture
    154,924 Most Valuable Professional on at

    Hi @Schwehr07 ,

    Just checking if you got the result you were looking for on this thread. Happy to help further if not.

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

  • Schwehr07 Profile Picture
    17 on at

    @WarrenBelz  Thanks for the response and the logic! I really appreciate you helping me understand the coding. It does work now, after taking out the extra comma (oops- that's embarrassing!). 

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 534

#2
WarrenBelz Profile Picture

WarrenBelz 416 Most Valuable Professional

#3
Valantis Profile Picture

Valantis 306

Last 30 days Overall leaderboard