cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper V
Helper V

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
Highlighted
Helper V
Helper V

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

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

2 REPLIES 2
Highlighted
Super User
Super User

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

@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."

Highlighted
Helper V
Helper V

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

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

Helpful resources

Announcements
secondImage

Demo-Extravaganza 2020

Check out these cool Power Apps & vote on your favorite!

secondImage

Robotic Process Automation

Let's talk about the solution provided by Microsoft for Robotic Process Automation (RPA)

secondImage

Community Highlights

Check out whats happening in Power Apps

secondImage

Community User Group Member Badges

FIll out a quick form to claim your community user group member badge today!

Top Solution Authors
Top Kudoed Authors
Users online (8,298)