cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
cgreen1983
Level: Powered On

Patch the last record of a user

Hi All,

 

I have an app which patches to a SP list upon submission of a button. Later on in the app, there is a need to patch to the last record, which works well when only one person is using it. If more than one person is using the app the "patch last record" request can end up patching to the wrong record by the wrong user. Im trying to get it to patch to the last record by the user, which would solve the issue.

 

Is anyone able to offer some help on the formula for this? My standard patch code is below, but I can't work out how to get it to only look at the last record of the app user?

 

 Any help would be appreciated.

 

Thanks,

 

Chris

 

Patch(Checks,Last(Checks),{ServiceNo: TextInput1.Text,Fleet_x0020_Number: TextInput2.Text,Depot:Dropdown4.Selected.Value,Driver:TextInput3.Text,PaxCount:Value(TextInput4.Text),VehicleQuality:TextInput5.Text,DvrQuality:TextInput6.Text,Comments:TextInput7.Text,LocationOff:TextInput9.Text,DvrIssue:TextInput14.Text,CPCValid:Checkbox1.Value});Navigate('S_Check Sent',ScreenTransition.None)

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Power Apps Staff CarlosFigueira
Power Apps Staff

Re: Patch the last record of a user

If this "later on in the app, there is a need to patch to the last record" always refers to the item that the app patched previously, then you can store the result of the first patch in a global variable, and then use that variable for the subsequent patch.

For example, if this is the code where you add a new item:

Patch(
    Checks,
    Defaults(Checks),
    { ... })

You can replace it with

Set(
    currentItem,
    Patch(
        Checks,
        Defaults(Checks),
        { ... }))

And when you want to update that item later in the app, you can use it:

Patch(
    Checks,
    currentItem,
    {
        ServiceNo: TextInput1.Text,
        Fleet_x0020_Number: TextInput2.Text,
        Depot: Dropdown4.Selected.Value,
        Driver: TextInput3.Text,
        PaxCount: Value(TextInput4.Text),
        VehicleQuality: TextInput5.Text,
        DvrQuality: TextInput6.Text,
        Comments: TextInput7.Text,
        LocationOff: TextInput9.Text,
        DvrIssue: TextInput14.Text,
        CPCValid: Checkbox1.Value
    });
Navigate('S_Check Sent',ScreenTransition.None)

View solution in original post

3 REPLIES 3
AndySid
Level 8

Re: Patch the last record of a user

How big is the list? You could try filtering in reverse and use the first function.

Power Apps Staff CarlosFigueira
Power Apps Staff

Re: Patch the last record of a user

If this "later on in the app, there is a need to patch to the last record" always refers to the item that the app patched previously, then you can store the result of the first patch in a global variable, and then use that variable for the subsequent patch.

For example, if this is the code where you add a new item:

Patch(
    Checks,
    Defaults(Checks),
    { ... })

You can replace it with

Set(
    currentItem,
    Patch(
        Checks,
        Defaults(Checks),
        { ... }))

And when you want to update that item later in the app, you can use it:

Patch(
    Checks,
    currentItem,
    {
        ServiceNo: TextInput1.Text,
        Fleet_x0020_Number: TextInput2.Text,
        Depot: Dropdown4.Selected.Value,
        Driver: TextInput3.Text,
        PaxCount: Value(TextInput4.Text),
        VehicleQuality: TextInput5.Text,
        DvrQuality: TextInput6.Text,
        Comments: TextInput7.Text,
        LocationOff: TextInput9.Text,
        DvrIssue: TextInput14.Text,
        CPCValid: Checkbox1.Value
    });
Navigate('S_Check Sent',ScreenTransition.None)

View solution in original post

cgreen1983
Level: Powered On

Re: Patch the last record of a user

Sorry for delay in replying, but the set and patch code worked well; thank you once again for all your help.

 

Chris

Helpful resources

Announcements
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

SecondImage

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Top Kudoed Authors (Last 30 Days)
Users online (4,265)