cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

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
CarlosFigueira
Power Apps
Power Apps

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
Resolver II
Resolver II

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

CarlosFigueira
Power Apps
Power Apps

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

Anonymous
Not applicable

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
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Are Your Ready?

Test your skills now with the Cloud Skill Challenge.

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Top Solution Authors
Top Kudoed Authors
Users online (81,485)