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

Patch order statements?

I have an on-premises sql database with beginning and ending odometer readings. When a user processes their mileage using our app, I'm trying to take the ending odometer and put it in the beginning field and then put zero in the ending field in the database. The following code works well but sometimes on difference devices it will patch in the wrong order, so I'll either end up with zero for beginning or beginning for both values. I thought putting them in separate statements would correct for this. Any thoughts from the community to help me? Much appreciation from anyone who does. 

Patch('[dbo].[VehicleReservations]', 
First(Filter('[dbo].[VehicleReservations]',
ID = Mileage_Gallery.Selected.ID)),
{BeginOdometer: LookUp('[dbo].[VehicleReservations]',
ID = Mileage_Gallery.Selected.ID,
EndOdometer)}
);
Patch('[dbo].[VehicleReservations]',
First(Filter('[dbo].[VehicleReservations]',
ID = Mileage_Gallery.Selected.ID)),
{EndOdometer: Value(0)}
);
Refresh('[dbo].[VehicleReservations]');
1 ACCEPTED SOLUTION

Accepted Solutions
PowerApps Staff CarlosFigueira
PowerApps Staff

Re: Patch order statements?

You can make multiple modifications with a single Patch statement:

UpdateContext({
    currentRecord:
    LookUp(
        '[dbo].[VehicleReservations]',
        ID = Mileage_Gallery.Selected.ID) });
Patch(
    '[dbo].[VehicleReservations]',
    currentRecord,
    {
        BeginOdometer: currentRecord.EndOdometer,
        EndOdometer: 0
    })

This should also be faster to execute than your previous code, as it only needs to perform calls to the data source (which are typically slow, since they have to go to the network).

Hope this helps!

View solution in original post

1 REPLY 1
PowerApps Staff CarlosFigueira
PowerApps Staff

Re: Patch order statements?

You can make multiple modifications with a single Patch statement:

UpdateContext({
    currentRecord:
    LookUp(
        '[dbo].[VehicleReservations]',
        ID = Mileage_Gallery.Selected.ID) });
Patch(
    '[dbo].[VehicleReservations]',
    currentRecord,
    {
        BeginOdometer: currentRecord.EndOdometer,
        EndOdometer: 0
    })

This should also be faster to execute than your previous code, as it only needs to perform calls to the data source (which are typically slow, since they have to go to the network).

Hope this helps!

View solution in original post

Helpful resources

Announcements
thirdimage

Power Automate 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

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors
Users Online
Currently online: 334 members 7,155 guests
Please welcome our newest community members: