cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
pcaracc
Level 8

Making sure a patch is successful

What is the current best practice to ensure that a patch to a SharePoint list is successful? I am building a dynamic expense reporting app and it is vital that submitted expenses are stored or that the user is notified that the expense was not stored so that they can try submitting again later.

 

I want to account for internet connection issues and any other issues that could occur that would interfere with a patch

1 ACCEPTED SOLUTION

Accepted Solutions
Power Apps Staff CarlosFigueira
Power Apps Staff

Re: Making sure a patch is successful

The documentation for the Errors function states the following:

The Patch function and other data functions don't directly return errors. Instead they return the result of their operation. After a data function executes, you can use the Errors function to obtain the details of any errors. You can check for the existence of errors with the [IsEmpty] function in the formula IsEmpty( Errors ( ... ) ).

So that's what you should be using after a Patch invocation to see if you had any errors.

 

However, this currently doesn't work for network issues (I've created a bug in the product team to fix it). As a workaround, you can also check the result of the Patch call - it returns the object as changed in the server. In network outage situations, the result is null. So you can use both cases to determine whether the Patch succeeded or not, something along the lines of the expression below.

UpdateContext({msg:"Executing Patch"});
UpdateContext({ patchResult: Patch(
    dataSourceName,
    Gallery1.Selected,
    { Value: Value(TextInput1.Text) }) });
UpdateContext({
    msg:If(
        Not(IsBlank(patchResult)) And IsEmpty(Errors(dataSourceName)),
        "Patch succeeded",
        "Patch failed")})

View solution in original post

11 REPLIES 11
Power Apps Staff CarlosFigueira
Power Apps Staff

Re: Making sure a patch is successful

The documentation for the Errors function states the following:

The Patch function and other data functions don't directly return errors. Instead they return the result of their operation. After a data function executes, you can use the Errors function to obtain the details of any errors. You can check for the existence of errors with the [IsEmpty] function in the formula IsEmpty( Errors ( ... ) ).

So that's what you should be using after a Patch invocation to see if you had any errors.

 

However, this currently doesn't work for network issues (I've created a bug in the product team to fix it). As a workaround, you can also check the result of the Patch call - it returns the object as changed in the server. In network outage situations, the result is null. So you can use both cases to determine whether the Patch succeeded or not, something along the lines of the expression below.

UpdateContext({msg:"Executing Patch"});
UpdateContext({ patchResult: Patch(
    dataSourceName,
    Gallery1.Selected,
    { Value: Value(TextInput1.Text) }) });
UpdateContext({
    msg:If(
        Not(IsBlank(patchResult)) And IsEmpty(Errors(dataSourceName)),
        "Patch succeeded",
        "Patch failed")})

View solution in original post

pcaracc
Level 8

Re: Making sure a patch is successful

Thank you for this @CarlosFigueira. I have part of my app using a custom flow in order to upload an image to a SharePoint document library. I want to have the app wait until the image is present in the document library before navigating to a different screen. Do you have any advice on how this could be done? 

 

Power Apps Staff CarlosFigueira
Power Apps Staff

Re: Making sure a patch is successful

You can return a value from the custom flow to PowerApps - so you can have the flow return a flag indicating that the upload is completed that you can use in your app.

pcaracc
Level 8

Re: Making sure a patch is successful

My only issue is that the flow doesn't have a PowerApps trigger, it is triggered by an HTTP request. 

 

Is there some type of WaitUntil(boolean) function in PowerApps or a way to do something similar? I could just do a wait/sleep until the data is uploaded to SP which I would check with a filter

Power Apps Staff CarlosFigueira
Power Apps Staff

Re: Making sure a patch is successful

There's no WaitUntil function or similar (feel free to create a new feature request in the PowerApps Ideas board for this). The closest thing that exists today would be to use a timer control, that every time the duration ends it would check whether the data is there. The timer would be set to repeat, and when the data is present it would set a flag that would "turn off" its repeat, and a flag to indicate to the app that the data is present.

zdames
Level: Powered On

Re: Making sure a patch is successful

Hi Carlos, I'm using this logic to check for a successfull patch, but am currently experiencing errors when I'm patching a collection to an online data source, wondering if you have any solutions for this?

Highlighted
Power Apps Staff CarlosFigueira
Power Apps Staff

Re: Making sure a patch is successful

What kind of errors are you seeing? Feel free to create a new thread ("new message") with this information, along with the session id (here's how to find it) where you see those errors, and someone should be able to help you.

Digit89
Level: Powered On

Re: Making sure a patch is successful

Hello,

How could you do this in a ForAll loop ? Can you know the result of each patch or only the loop ?

 

The problem is you can't set a dynamic var name, like

UpdateContext({ patchResult[i]: ....... 
Power Apps Staff CarlosFigueira
Power Apps Staff

Re: Making sure a patch is successful

You're correct, there's no "array" variables yet for PowerApps. One possible solution is to have a collection that would store the results of all patch invocations. For example, if you have a collection of records ('recordsToPatch') with 3 fields (Id, Name, Age), and I want to patch all records in the data source to increase the Age, I could have the following expression:

Clear(patchResults);
ForAll(
    recordsToPatch,
    Collect(
        patchResults,
        {
            Id: Id,
            patchResult: Patch(
                DataSourceToPatch,
                { Id: Id, Name: Name },
                { Age: Age + 1 })
        }))

At the end you have a collection with two columns: id and patchResult. If you want to know which ones failed, you can filter that collection:

Filter(patchResults, IsBlank(patchResult))

And look at the ids of this.

 

Helpful resources

Announcements
thirdimage

Coming Soon: T-Shirt Design Contest

Keep your eyes open for our upcoming T-shirt design contest!

thirdimage

Power Apps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

Top Solution Authors
Top Kudoed Authors
Users online (7,114)