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

Community site session details

Session Id : /9yZT9WkHpSmjYf/ni1a/S
Power Apps - Building Power Apps
Answered

Powerapps - best practice on using patch?

Like (0) ShareShare
ReportReport
Posted on 13 Mar 2022 19:00:40 by 1,095

I have just spent quite some time searching for a strange error in my app.

 

When i press a button i run two patch functions.

patch 1 updated table 1 data and patch 2 updated table 2 data.

table 1 and table 2 have an relationship.

 

in my app when i press a row in a gallery i do set "thisItem" to an variable.

set(varThisItem;gallery1.selected)

Then i navigate to a new screen

on this screen i have some textboxes, comboboxes that i populate using

varThisItem.column1 etc.

 

then to save the data from the textboxes and comboboxes i use patch to update some of the table1 columns.

the other patch function that update table2 do so just to create a new record and log that a change have been made by a user.

 

but for some reason som lookup columns is set to blank. i could not figure out why.

 

but i solved this by separating the code and first run the patch on table1 then i added a second button and auto-pressed it with select(button2) and then run the patch for table2.

 

i cant explain why i got it to work.

it feels like the code work to fast so the datasource does not have time to update.... by separating the code i guess i get some delay.

can this be true?

 

i have noticed that i do benefit from adding some timers and to delay the code sometimes.

but i can not figure out when i SHOULD use it and when i dont need to....

 

looking for some kind of explanation to better understand why i need so many controls in my apps just to have them hidden and run code from...

I have the same question (0)
  • v-jefferni Profile Picture
    on 16 Mar 2022 at 07:30:41
    Re: Powerapps - best practice on using patch?

    Hi @Oskarkuus ,

     

    Your suspicion is basically right on the data source delay. The reason is from the LookUp columns you mentioned, they will rely on the records having created successfully within the main source. Using the Timer control will normally around this problem but like you said there will be too many hidden controls and make app makers unhappy.

     

    There is another workaround, you can try and use a variable to save the result of the first Patch and use it for the second one:

    Set(varPID, Patch(DataSource1, Defaults(DataSource1),{...}).ID);
    Patch(DataSource2,Defaults(DataSource2),{LookUpColumn:LookUp(Choices(DataSource2.LookUpColumn),ID = varPID)})

     

    Hope this helps.

     

    Best regards,

    Community Support Team _ Jeffer Ni
    If this post helps, then please consider Accept it as the solution to help the other members find it.

  • Oskarkuus Profile Picture
    1,095 on 17 Mar 2022 at 06:50:06
    Re: Powerapps - best practice on using patch?

    hm that was news to me.

    so do i understand you correct, you mean that i can save a patch functions result in a variable?

    Set(varPID, Patch(DataSource1, Defaults(DataSource1),{...}).ID);

    will this variable be the id-value of the newly created row in datasource1?
    but wont i need to run this patch aswell so it actually creates the new row?

     

     

     

     

  • Verified answer
    v-jefferni Profile Picture
    on 17 Mar 2022 at 07:10:37
    Re: Powerapps - best practice on using patch?

    Hi @Oskarkuus ,

     

    Yes, it will be the id value of the newly created row in datasource1. Since the Patch function is in the variable, you will have the Patch function fired and get the returned result being saved into the variable. If you make a bulk update using ForAll/Patch or UpdateIf, you can even append it into Collect/ClearCollect functions to create a collection with all the updated/created records.

     

    Best regards,

    Community Support Team _ Jeffer Ni
    If this post helps, then please consider Accept it as the solution to help the other members find it.

  • Oskarkuus Profile Picture
    1,095 on 17 Mar 2022 at 16:24:14
    Re: Powerapps - best practice on using patch?

    Great

    Did not know i could fire a patch as i was swrring a variable and get the id from the patch.

     

    This solves a few things by removing timers and buttons to call. 

     

     

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Chiara Carbone – Community Spotlight

We are honored to recognize Chiara Carbone as our Community Spotlight for November…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 686 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 433 Super User 2025 Season 2

#3
wolenberg_ Profile Picture

wolenberg_ 266 Moderator

Last 30 days Overall leaderboard
Loading complete