cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
bolin-stratus
Post Partisan
Post Partisan

Is it possible to use an If statement within a patch function?

Is it possible to use an If statement within a patch function? When I try, there is a formula error. 

 

// Need to add an IF within the Patch function
// WKS until I add IF
Patch( 'SPO-List-Name', Defaults( 'SPO-List-Name' ),
  {
      'Location': txtLocation.Text,
      'City': txtCity.Text,
      'Country': txtCountry.Text,
  }
)

// I need to insert this IF into Patch function 
If( dropdownA.SelectedText.Value = "One",
  'Field': txtOne.Text,
  'Field': txtTwo.Text,
)

1 ACCEPTED SOLUTION

Accepted Solutions

Hey @mdevaney - Thanks for the quick response.  Your solution does not work for me but the one below does. 

 

Set a variable on the Submit button OnSelect and have that run immediately before running the patch.

// OnSelect (Submit button)
If( dropdownA.SelectedText.Value = "One",
  Set(_fieldVar, txtOne.Text),
  Set(_fieldVar,txtTwo.Text)
)

// Then run Patch
Patch( 'SPO-List-Name', Defaults( 'SPO-List-Name' ),
  {
      Location: txtLocation.Text,
      City: txtCity.Text,
      Country: txtCountry.Text,
      Field: _fieldVar
  }

View solution in original post

6 REPLIES 6
mdevaney
Super User III
Super User III

@bolin-stratus 

Have you already tried this approach?

 

Patch(
  'SPO-List-Name',
  Defaults('SPO-List-Name'),
  {
      'Location': txtLocation.Text,
      'City': txtCity.Text,
      'Country': txtCountry.Text,
      'Field': If(dropdownA.SelectedText.Value = "One", txtOne.Text, txtTwo.Text)
  }
)

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

Hey @mdevaney - Thanks for the quick response.  Your solution does not work for me but the one below does. 

 

Set a variable on the Submit button OnSelect and have that run immediately before running the patch.

// OnSelect (Submit button)
If( dropdownA.SelectedText.Value = "One",
  Set(_fieldVar, txtOne.Text),
  Set(_fieldVar,txtTwo.Text)
)

// Then run Patch
Patch( 'SPO-List-Name', Defaults( 'SPO-List-Name' ),
  {
      Location: txtLocation.Text,
      City: txtCity.Text,
      Country: txtCountry.Text,
      Field: _fieldVar
  }

View solution in original post

Anonymous
Not applicable

yes It will . Its working for me Please code as below 

 

Set(_oldRecord,LookUp(SP_ListName,EmployeeEmail = ComboBox1.Selected.Mail));

 

Patch( SP_ListName, _oldRecord,  

Field: If( dropdownA.SelectedText.Value = "One", txtOne.Text, txtTwo.Text),    

  City: txtCity.Text,  

  Country: txtCountry.Text   } )

 

 

Thanks @Anonymous for the example. 

hi,

 

I'm trying your formula but getting an error mssg. Can have a look into it and let me know what I'm doing wrong. Do note the field is a date field


If(AccessType_Radio.Selected.Value = “Permanent”,

    Set(varExpiry,Blank()),Set(varExpiry,ExpiryDate_DatePicker.SelectedDate)

)

 

Patch( WiFiAccess,Defaults(WiFiAccess);

{Title:Name_Input.Text&Now(),

AccessRequestedFor:AccessRequest_Input.Text,

AccessType:AccessType_Radio.Selected.Value,

ExpiryDate: varExpiry});

Freundt
Regular Visitor

Hi,

 

here's my solution for patch inside an if-Statement:

 

//define state onSelect for Button - e.g. Sstate 3 = begin, 2 = new, 3 = end

UpdateContext({Status: Mod(state, 3) + 1 });

//Patch on State
If(state = 3, Patch(SharepointList, Defaults(SharepointList), {Field: "state 3"}), If(state=2, Patch(SharepointList, Defaults(SharepointList), {Field: "state 2"}),Patch(SharepointList, Defaults(SharepointList), {Field: "state 1"})))

 

also works with multiple patch-fields

 

UpdateContext({Status: Mod(state, 3) + 1 });

If(Status = 3, (Patch(SharepointList, Defaults(SharepointList), {Field1: <yourValue>}, {Field2: "<yourText>"})), (If(Status = 1, (Patch(SharepointList, Defaults(SharepointList), {Field1: <yourValue>}, {Field2: "<yourText>"})))));
If(Status = 2, Reset(Field1); Reset(Field2))

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.

Users online (1,397)