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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Any ideas, how to simp...
Power Apps
Answered

Any ideas, how to simplify/improve this code?

(0) ShareShare
ReportReport
Posted on by 321

Hi, 

 

Quite the novice in PowerApps, and I have some code in my App which works fine, but I am aware that it can likely be improved/tidied up.

The code is;

 

If(cb_action_to_take.Selected.Value = "Reject Commission",UpdateContext({loc_AppRej:true}), cb_action_to_take.Selected.Value = "Approve Commission",UpdateContext({loc_AppRej:true}),cb_action_to_take.Selected.Value = "Request more info",UpdateContext({loc_more_info:true}), cb_action_to_take.Selected.Value = "Add to KIV", UpdateContext({loc_add_to_KIV:true}), cb_action_to_take.Selected.Value = "Approve Consultation", UpdateContext({loc_consultation_AppRej:true}), cb_action_to_take.Selected.Value = "Reject Consultation", UpdateContext({loc_consultation_AppRej:true}), cb_action_to_take.Selected.Value = "Add to Workplans", UpdateContext({loc_add_to_WP:true}))

 

So, cb_action_to_take is a Combobox pulling from my 'Status' column (Choice) in a SharePoint List.

 

The quoted text, e.g. "Reject Commission" is the names of the choices, then the UpdateContext triggers an individual popup depending on which choice is selected in the combobox. 

 

As I mentioned, quite a novice and thinking this code could be improved/tidied up.

Any ideas what a better (potentially more dymanic) way to code this would be?

 

Thanks.

Categories:
  • maskwer Profile Picture
    53 on at

    You can use the Switch function.

  • Verified answer
    ramzez Profile Picture
    312 on at

    Would this work?

    Switch(cb_action_to_take.Selected.Value,
     "Reject Commission", UpdateContext({loc_AppRej: true}),
     "Approve Commission", UpdateContext({loc_AppRej: true}),
     "Request more info", UpdateContext({loc_more_info: true}),
     "Add to KIV", UpdateContext({loc_add_to_KIV: true}),
     "Approve Consultation", UpdateContext({loc_consultation_AppRej: true}),
     "Reject Consultation", UpdateContext({loc_consultation_AppRej: true}),
     "Add to Workplans", UpdateContext({loc_add_to_WP: true})
    )
  • JimboSey Profile Picture
    321 on at

    Works exactly as I needed.

     

    Thank 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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 396 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 323

#3
WarrenBelz Profile Picture

WarrenBelz 193 Most Valuable Professional

Last 30 days Overall leaderboard