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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Patch statement takes ...
Power Apps
Unanswered

Patch statement takes forever... sometimes... why?

(0) ShareShare
ReportReport
Posted on by 1,259 Moderator

This is my Patch statement.  Sometimes it runs very fast.  Other times, it can hit this statement and take minutes (really up to 5-10) to finish executing.  Eventually it does.

 

How can I rewrite this so this doesn't happen.

 

FYI:  CDMRequests is a VERY small Sharepoint List with about 10 records.  "varSelectedRequestID" is a variable that gets set with what is in the gallery and I have validated the value is always there and correct.

 

Simply put, the system doesn't like this Patch command some of the time and I'm hoping there is some way to rework it so that it works quickly EVERY time.

 

This is a HUGE problem for me, so ALL help is greatly appreciated!

Patch(
CDMRequests,
LookUp(
CDMRequests,
ID = varSelectedRequestID
),
{Status: EndStatus}
)

Categories:
I have the same question (0)
  • joyle Profile Picture
    Microsoft Employee on at

    Is there any chance that the Patch function is being called multiple times, for each gallery item for example?

    Maybe you can set some variables as a way to debug your process:

    Set(start, Now()); // when the process has started
    Set(record, LookUp(...)); // call LookUp function alone and check how long to process it
    Set(diff1, Now() - start); // captures how much time LookUp took
    Set(start, Now()); // reset
    Patch(Table, record, {...}); // call Patch function alone
    Set(diff2, Now() - start) // captures how much time Patch took

    Not ideal, but maybe this will give you better info about the root of your problem.

  • subsguts Profile Picture
    1,259 Moderator on at

    @joyle Thanks for the suggestions.  I will try that and see if I can isolate the problem.  I am sure it's not being called multiple times as I already have some variable in the code for debugging purposes.  I definitely like your  idea to get the timings on each operation though.  Great idea.

  • Ny8C Profile Picture
    24 on at

    Hi,

    Have you tried to use instead of variable just Galleryxy.Selected.ID? I’m not often use variable for this purpose and works like a charm.

  • subsguts Profile Picture
    1,259 Moderator on at

    I'll try that, but I think @ShaneYoung , suggested in his videos that he always store the ID from the Gallery in a variable because he had issues referencing the gallery directly for that information, due to refreshes, etc. I think.  

  • subsguts Profile Picture
    1,259 Moderator on at

    Latest info on this ever growing annoyance, is now it is pausing on this particular code.  I've put in a variable, and so I know that it didn't get past this patch command.  Remember, this doesn't happen ever time.  I'm clicking buttons to cause this to happen multiple times and let's say every 10th time it takes forever (minutes) for this statement to happen.  Maybe the Lookup has been fixed, we'll see, but this is another statement in the same button OnSelect and I'm not sure why this would EVER take a long time since is just inserting a new record into a SharePoint List.  Shouldn't this be super fast?

     

    Patch(
    CDMRequestTracking,
    Defaults(CDMRequestTracking),
    {RequestID: varSelectedRequestID},
    {'Begin Status': StartStatus},
    {'End Status': EndStatus},
    {ReviewerComments: varHoldReviewerComments},
    {RequestorComments: varHoldRequestorComments},
    {EndStatusChanged: varBeginStatus}
    );

     

    @joyle 

  • subsguts Profile Picture
    1,259 Moderator on at

    Yet another failure at a different point.  Here's the rewrite of the code separating the Lookup.  It made it past the Lookup, but then hung on the next Patch statement because I saw the "here1a" on my label, but it stopped there.  

     

    @joyle why is this happening, I can't roll this App out to users unless I know that this is working consistently and I really have no idea why this Patch statement should take minutes to complete, it should be seconds.  Any suggestions as to what I can do?  Is this a SharePoint issue?

     

    Keep in mind this doesn't hang at this point ever time.  It is intermittent and also posted here is another place it hung, which was not this one.  There doesn't appear to be a reason why the system decides not be be able to run these Patch commands most of the time very quickly and other times it can take what will seem like forever to anyone using this.  It really is making my brain hurt as there is no reason for this 🙂

     

    Edit: This has now been running for several minutes.  Eventually it will complete, but I don't think users will wait minutes for what should be a simple save.

     

    Set(
    record,
    LookUp(
    CDMRequests,
    ID = varSelectedRequestID
    )
    );
    Set(
    varLocation,
    "here1a"
    );
    Patch(
    CDMRequests,
    record,
    {Description: txtDescription.Text},
    {AdditionalCommentsInformation: txtAdditionalCommentsInformation.HtmlText},
    {Status: EndStatus}
    );

  • subsguts Profile Picture
    1,259 Moderator on at

    Update, a person I worked with pointed out my patch statement has a lot of extra { } that were not syntactically correct.  Not sure what the extra brackets did, but I've taken them out and now are in the process of retesting the App.  I'm hoping that having the extra brackets caused the Patch to sometimes take longer or confuse the system, but most of the time it still did the patch.  Maybe it was doing the patch mutlple or something else since it did work most of the time.

    I will update after testing if this truly fixed the issue or it was something else.  Ideas on what the extra curly brackets would do would be GREAT info if anyone knows.

     

    BEFORE: (bolded curly brackets are remove in AFTER)

    Patch(
    CDMRequests,
    record,
    {Description: txtDescription.Text},
    {AdditionalCommentsInformation: txtAdditionalCommentsInformation.HtmlText},
    {Status: EndStatus}
    );

     

    AFTER:

    Patch(
    CDMRequests,
    record,
    {Description: txtDescription.Text,
    AdditionalCommentsInformation: txtAdditionalCommentsInformation.HtmlText,
    Status: EndStatus}
    );

  • subsguts Profile Picture
    1,259 Moderator on at

    I did confirm it is only being called once.  I believe there is some issue, intermittedly with connecting to the data source, SP List in my case.

  • Ny8C Profile Picture
    24 on at

    Just an idea, is the submit button/icon is in the gallery? Then use the following way: patch( datasourse, ThisItem,{}) and make sure the Title is not mandatory in the sp list. It can cause also problem as sometimes allow to oatch sometimes not.

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard