web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / How do I update a drop...
Power Apps
Answered

How do I update a dropdown field using a Switch statement correctly?

(1) ShareShare
ReportReport
Posted on by 301
I have a form that I am trying to use to enter in some data into my list (myList). Depending on what fields they complete some other columns become visible. So when a user selects a value in a dropdown field, it changes the text that is displayed on a button (this part is working). Based on the text on the button, I want to set the value of another dropdown. This is what my code looks like so far in the OnSelect of my button
 
UpdateContext(
    {
        Error1: If(
            IsBlank(Trim(DataCardValue2.Value)),
            "This field is required",
            ""
        ),
        SumError: If(
            IsBlank(SumAmntVar),
            "This field is required",
            ""
        ),
        AgError: If(
            IsBlank(DataCardValue4.Selected),
            "This field is required",
            ""
        ),
        DetailError: If(
            IsBlank(Trim(DataCardValue6.Value)),
            "This field is required",
            ""
        ),
        AmntError: If(
            IsBlank(Trim(DetAmt_Value.Value)),
            "This field is required",
            ""
        )
    }
);
Switch(
    btnSubmit.Text,
    "First Scenario",
    If(
        !IsBlank(Error1) || !IsBlank(SumError) || !IsBlank(AgError) || !IsBlank(DetailError) || !IsBlank(AmntError),
   // Has errors - don't submit
        Notify(
            "Please complete all required fields before submitting.",
            NotificationType.Error
        ),
   // No errors - submit
        If(
            !IsBlank(SharePointIntegration.Selected),
            Patch(
                'myList',
                //SharePointIntegration.Selected,
                LookUp('myList', ID =ThisItem.ID),
                {
                    Status: {Value: "Pending 1st approval"}
                }
            )
        );
        SubmitForm(myForm);
        //RequestHide(); Refresh('myList');
        Notify(
            "Request submitted successfully!",
            NotificationType.Success
        )
    ),
    "Second Scenario",
    If(
        !IsBlank(Error1) || !IsBlank(SumError) || !IsBlank(AgError) || !IsBlank(DetailError) || !IsBlank(AmntError),
   // Has errors - don't submit
        Notify(
            "Please complete all required fields before submitting.",
            NotificationType.Error
        ),
   // No errors - submit
        If(
            !IsBlank(SharePointIntegration.Selected),
            Patch(
                'myList',
                //SharePointIntegration.Selected,
                LookUp('myList', ID =ThisItem.ID),
                {                            
                    Status: {Value: "Pending 2nd Approval"}             
                }
            )
        );
        SubmitForm(myForm);
        Notify(
            "Request submitted successfully!",
            NotificationType.Success
        )
    )
);
 
 
After the validation is done, the first scenario in my Switch statement works and the Status field is updated correctly. However when the second scenario is the case, the Status field is not being updated. What am I doing wrong here? I just want to update the Status field in each scenario...appreciate the eyes and help.
 
 
Update: I had a typo on the original snippet I posted, but have now corrected it. The issue is still happening.
Categories:
I have the same question (0)
  • Suggested answer
    Bezanca Profile Picture
    416 on at

    Hello @Spawn10

    I think its because you've got double quotes on the second status update? Try taking a set of quotes out and see if that work?

     
    Status: {Value: ""Pending 2nd Approval""}
    This should be - 

    Status: {Value: "Pending 2nd Approval"}

    Thanks!
    Adam
  • Spawn10 Profile Picture
    301 on at
    Hello @Bezanca
    Thanks for the response...the double quotes was a typo on my part as I was posting it on here. The issue exits with using only one set of quotes as well. So on the app, I am using it correctly. 
    Status: {Value: "Pending 2nd Approval"}
     
  • Suggested answer
    Bezanca Profile Picture
    416 on at
    I thought that was too easy ;)

    Here's a suggested amendment which groups each patch + submitform + notify together. 

    I don't have a way of testing this though so can you give this a go and report back?

    THanks!

     
    
    Switch(
        btnSubmit.Text,
        "First Scenario",
        If(
            !IsBlank(Error1) || !IsBlank(SumError) || !IsBlank(AgError) || !IsBlank(DetailError) || !IsBlank(AmntError),
            Notify(
                "Please complete all required fields before submitting.",
                NotificationType.Error
            ),
            // Group all success logic in parentheses
            (
                If(
                    !IsBlank(SharePointIntegration.Selected),
                    Patch(
                        'myList',
                        LookUp('myList', ID = ThisItem.ID),
                        { Status: {Value: "Pending 1st approval"} }
                    )
                );
                SubmitForm(myForm);
                Notify(
                    "Request submitted successfully!",
                    NotificationType.Success
                )
            ) // this closes the grouped success block
        ),
        "Second Scenario",
        If(
            !IsBlank(Error1) || !IsBlank(SumError) || !IsBlank(AgError) || !IsBlank(DetailError) || !IsBlank(AmntError),
            Notify(
                "Please complete all required fields before submitting.",
                NotificationType.Error
            ),
            // Group all success logic in parentheses
            (
                If(
                    !IsBlank(SharePointIntegration.Selected),
                    Patch(
                        'myList',
                        LookUp('myList', ID = ThisItem.ID),
                        { Status: {Value: "Pending 2nd Approval"} }
                    )
                );
                SubmitForm(myForm);
                Notify(
                    "Request submitted successfully!",
                    NotificationType.Success
                )
            ) // matching close
        )
    )
    
     
  • Spawn10 Profile Picture
    301 on at
    Unfortunately that grouping did not resolve it. 
  • Verified answer
    WarrenBelz Profile Picture
    153,117 Most Valuable Professional on at
    I will add some condensed code here - I assume that the reason for testing that SharePointIntegration.Selected is not blank is for new records ? Note that this does not always work if you have selected an existing record before adding a new one. I also assume that the Status field is not on the Form - if so, the SubmitForm after the Patch will overwrite whatever you have Patched.
    With(
       {
          _Error: 
          If(
             IsBlank(Trim(DataCardValue2.Value)) ||
             IsBlank(SumAmntVar) ||
             IsBlank(DataCardValue4.Selected) ||
             IsBlank(Trim(DataCardValue6.Value)) ||
             IsBlank(Trim(DetAmt_Value.Value)),
             "This field is required",
             Blank()
          )
       },
       If(
          !IsBlank(_Error),
          Notify(
             "Please complete all required fields before submitting.",
             NotificationType.Error
          ),
          !IsBlank(SharePointIntegration.Selected),
          Patch(
             'myList',
             {   
                ID: ThisItem.ID,
                Status: 
                {
                   Value: 
                   Switch(
                      btnSubmit.Text,
                      "First Scenario",
                      "Pending 1st approval",
                      "Second Scenario",
                      "Pending 2nd Approval"
                   )
                }
             }
          )
       );
       SubmitForm(myForm);
       Notify(
          "Request submitted successfully!",
          NotificationType.Success
       )
    );
     
    Please click Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it a Like.
    Visit my blog Practical Power Apps    LinkedIn   
  • Spawn10 Profile Picture
    301 on at
    Thanks for the response...That is also still giving me the same behavior. It records the first scenario with the data into the list, but that status column is not captured for the second scenario
  • WarrenBelz Profile Picture
    153,117 Most Valuable Professional on at
    What is the Formula for the Text of btnSubmit ? Replace btnSubmit.Text with that in the formula and see if it works. This is the most basic of Switch statements and should work. If you put this on a Label
    Switch(
       btnSubmit.Text,
       "First Scenario",
       "Pending 1st approval",
       "Second Scenario",
       "Pending 2nd Approval"
    )
    do you see the value you are expecting when the button Text shows the relevant property ? The code works here fine when tested.
     
    Please click Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it a Like.
    Visit my blog Practical Power Apps    LinkedIn   
     
  • Spawn10 Profile Picture
    301 on at
    You are right, when I put that Switch in a label, I see it grabbing the right response for each scenario. I think the issue, is that the value of the status column I am trying to update is not getting to the list...when I test the first scenario, it works like a charm. When I test the second scenario, the label shows the right value but that value does not make it to the SharePoint list. 
    In the second scenario, it submits all the other columns but not the status column that I am trying to update with the switch...that column shows up as blank. That is only for the second scenario, as the first one works. 
     
    I am wondering if the SubmitForm(myForm) is overwriting it, somehow.
  • WarrenBelz Profile Picture
    153,117 Most Valuable Professional on at
    That was my suspicion. Firstly, what is the formula on the Text of the button ? Also, is a Data Card containing the Status field on the Form ?
  • Spawn10 Profile Picture
    301 on at
    This is what the Text of the button has 
     
    If(
      IsBlank(TASKValue.Selected.Value),"Select A Task",
      If(
         TASKValue.Selected.Value in taskList,
         "First Scenario",
         "Second Scenario"
      )
     
    The Update on the Status Datacard is blank

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 765 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 272

Last 30 days Overall leaderboard