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

How to combine 2 patch statements

Hey all!

I have a patch statement that unfortunately is causing my flow to trigger twice and was hoping you could help me roll it into a single statement to help eliminate the patch from my troubleshooting.


Context of what patch is doing.
First patch sets the old record in SQL to current flag false
Second patch sets the new record in SQL to approved, adds approval date, and sets the current flag of the record to true.

Here it is:

Patch(
'[dbo].[SoFriendly]',
First(
Filter(
'[dbo].[SoFriendly]',
Emp_Per_ID = Value(DataCardValue2.Text)
)
),
{Current_Flag: false}
);
Patch(
'[dbo].[SoFriendly]',
First(
Filter(
'[dbo].[SoFriendly]',
Emp_Per_ID = Value(DataCardValue1.Text)
)
),
{Payroll_Approval_Status: Payroll_Approval_Dropdown.SelectedText.Value, Payroll_Approval_Date: Date_Label.SelectedDate, Current_Flag: true}
);Navigate(Landing);Reset(Payroll_Approval_Dropdown);

1 ACCEPTED SOLUTION

Accepted Solutions
Friendly
Level: Powered On

Re: How to combine 2 patch statements

I believe it is the following but will have to try tomorrow when I am back in the office.

 

Patch(
'[dbo].[SoFriendly]',
First(
Filter(
'[dbo].[SoFriendly]',
Emp_Per_ID = Value(DataCardValue2.Text)
)
),
{Current_Flag: false},

First(
Filter(
'[dbo].[SoFriendly]',
Emp_Per_ID = Value(DataCardValue1.Text)
)
),
{Payroll_Approval_Status: Payroll_Approval_Dropdown.SelectedText.Value, Payroll_Approval_Date: Date_Label.SelectedDate, Current_Flag: true}
);Navigate(Landing);Reset(Payroll_Approval_Dropdown);

View solution in original post

3 REPLIES 3
Friendly
Level: Powered On

Re: How to combine 2 patch statements

I believe it is the following but will have to try tomorrow when I am back in the office.

 

Patch(
'[dbo].[SoFriendly]',
First(
Filter(
'[dbo].[SoFriendly]',
Emp_Per_ID = Value(DataCardValue2.Text)
)
),
{Current_Flag: false},

First(
Filter(
'[dbo].[SoFriendly]',
Emp_Per_ID = Value(DataCardValue1.Text)
)
),
{Payroll_Approval_Status: Payroll_Approval_Dropdown.SelectedText.Value, Payroll_Approval_Date: Date_Label.SelectedDate, Current_Flag: true}
);Navigate(Landing);Reset(Payroll_Approval_Dropdown);

View solution in original post

Eelman
Level 10

Re: How to combine 2 patch statements

Seems like your code is updating 2 different ID's in SQL, is this correct? If so, and your Flow is "when an item is created or modified", then it will run twice because you are making 2 modifications. If this is the case, try putting a condition in your Flow that stops this

 

Eg. if Current_Flag = false do nothing else do your Flow.

 

I don't think your second code bit will work? Haven't tested it, just doesn't look like it would.

Friendly
Level: Powered On

Re: How to combine 2 patch statements

Yes updating two records in SQL.  The patch definitely works as is.  I could have as many patches as I want like that, as long as they all point to valid data sources and the data I'm plugging in matches, why not.

I will try and figure out how to stop flow based on your recommendation and report back.

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,223)