Skip to main content

Notifications

Power Apps - Building Power Apps
Answered

64 different scenarios, how to write an easy Patch statement towards Sharepoint List

(0) ShareShare
ReportReport
Posted on by 187

Hi all,

 

I've been thinking long and hard for an easy fix for the following scenario but I need some help.

 

On one of my screens I have 4 toggle buttons to indicate if a certain engine filter has been replaced true/false.
If true, the user needs to indicate how many are replaced and the app will calculate the remaining amount. I have a lookup to a stocklist to show quantity in stock and then minus the number replaced you end up with remaining quantity of stock.

Since I've got 4 toggles with true/false options and the situation that in case true I have to patch the remaining amount and in case false I need to patch the quantity still in stock, I decided to write out the 16 scenarios, like this in case all four toggles are true:

If(ToggleFuelFilters.Value = true && ToggleAirFilters.Value = true && ToggleLubricatingFilters.Value = true && ToggleRacorFilters.Value = true,
Patch('Stock Liquidos',{
Title: "-",
Engine: DDEngine.Selected.Value,
'Fuel Filter 1': Value(RemainingFF1.Text),
'Fuel Filter 2': Value(RemainingFF2.Text),
'Air Filter 1': Value(RemainingAF1.Text),
'Lubricating Filter 1': Value(RemainingLF1.Text),
'Racor Filter 1': Value(RemainingRFilter1.Text)}));

so as you can see, only the remaining values are patched.

The next scenario is as follows where the fourth toggle is set to false:

f(ToggleFuelFilters.Value = true && ToggleAirFilters.Value = true && ToggleLubricatingFilters.Value = true && ToggleRacorFilters.Value = false,
Patch('Stock Liquidos',{
Title:"-",
Engine: DDEngine.Selected.Value,
'Fuel Filter 1': Value(RemainingFF1.Text),
'Fuel Filter 2': Value(RemainingFF2.Text),
'Air Filter 1': Value(RemainingAF1.Text),
'Lubricating Filter 1': Value(RemainingLF1.Text),
'Racor Filter 1': Value(OnboardRacorFilter1.Text)}));

 

and as you can see for the last option (Racor replaced is false) I patch the quantity still in stock.

 

This works like a charm and everything is happy and shiney.

 

However, I now need to create a screen where there are 6 toggle options true/false and for each of those toggles I again need to patch either the remaining amount after replaced (true scenario) or the still onboard quantity (false scenario).

I have done the math and found out this would require to write 64 different scenario's to cater for each and everyone of the toggle scenarios, like all 6 are true, 5 are true, one is false etc. etc.

 

I am pretty sure that I am currently dealing with it "the hard way" and there must be an easier solution for this.
I was thinking about a patch per toggle, like

 

if(ToggleFuelFilters.Value = true,
Patch(Stock Liquidos,
'Fuel Filter 1': Value(RemainingFF1.Text),
'Fuel Filter 2': Value(RemainingFF2.Text)),
'Fuel Filter 1': Value(OnboardFF1.Text),
'Fuel Filter 2': Value(OnboardFF2.Text))

and then continue with the next toggle. However I am struggling to make sure that all of the 6 toggles are written to my Sharepoint List in one single record. I have the feeling that if I do the approach above, I will get 6 records in total where the first record only contains the fuel filter information, second record the airfilters information etc. etc.

 

Who can help my brain-freeze to melt? Perhaps a collection is the way forward or variables? Many many thanks in advance for guidance provided!

Categories:
  • RandyHayes Profile Picture
    RandyHayes 76,287 on at
    Re: 64 different scenarios, how to write an easy Patch statement towards Sharepoint List

    @debarbanson 

    If you do it that way, you will need to make sure you are providing a value for both true and false conditions.

    In the formula I sent you, that would be used if you did NOT want to specify a column to patch.

     

    The only additional bit to save you some keystrokes is that you don't need the "true" in your formulas.  ToggleFuelFilters_2.Value will already be true or false, comparing it again to true is redundant.  So:

       If(ToggleFuelFilters_2.Value, Value(RemainingFF1_2.Text), Value(OnboardFuelFilter1_2.Text))

    Is equivalent to what you had but less keystrokes.  

    Just thought I would mention that since you have a lot of conditions to add.

     

    Otherwise...you are on your way!

  • debarbanson Profile Picture
    debarbanson 187 on at
    Re: 64 different scenarios, how to write an easy Patch statement towards Sharepoint List

    Dear Randy,

     

    Many many thanks, you've made my day (or night actually since it's 00:52 AM here 🙂
    Tried your approach with 2 toggles and it works perfectly, done it as follows:

    Patch('Stock Liquidos',
    Defaults('Stock Liquidos'),
    {Title: "-",
    'Registration Date': DatePicker1_2.SelectedDate,
    Engine: DDEngine.Selected.Value,
    'Fuel Filter 1': If(ToggleFuelFilters_2.Value = true, Value(RemainingFF1_2.Text), Value(OnboardFuelFilter1_2.Text)),
    'Lubricating Filter 1': If(ToggleLubricatingFilters_2.Value = true, Value(RemainingLF1_2.Text), Value(OnboardLubricationFilter1_2.Text))});

     

    And you are correct, I am not overwriting the current existing record but creating a new record per registration date. In that way I can easily "count" how many registrations for a specific engine have been made (gonna put some Power BI reporting on the Sharepoint list as well).

    Once again many thanks!

  • Verified answer
    RandyHayes Profile Picture
    RandyHayes 76,287 on at
    Re: 64 different scenarios, how to write an easy Patch statement towards Sharepoint List

    @debarbanson 

    So, Patch will patch many records together one after another and create one record containing all of the values from left to right (note: overwriting prior parameters if specified).

     

    So, how I accomplish this is like the following:

     

    Patch('Stock Liquidos',
     Defaults('Stock Liquidos'),
     {someCommonColumn1: "SomeValue",
     someCommonColumn2: "SomeValue"
     },
     If(Toggle1.Value, {someToggle1Column: "SomeValue1"}, {}),
     If(Toggle2.Value, {someToggle2Column: "SomeValue2"}, {}),
     etc...
    )

    This makes it pretty manageable.

     

    I also noticed that you were not specifying a record in your original patch formulas.  The above created a new record.  If you are updating existing records, then make sure you specify the record from the datasource in the patch.

     

    I hope this is helpful for you.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Microsoft Kickstarter Events…

Register for Microsoft Kickstarter Events…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 145,580

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,909

Leaderboard