Code Snippet maps status codes with text

Chapter - 08

Visit to buy the book on Citizen Development https://go.amitpuri.com/buynow

Code Snippet #2

Maps status codes with text

This code snippet uses the Switch function, which is a powerful tool for handling multiple conditional cases. It is designed to evaluate an expression and return different results based on the value of that expression.

   Switch(
    ThisItem.'Referral Status',
    'Referral Status (Referrals)'.'Referral bonus settled',
    "Referral bonus settled",
    'Referral Status (Referrals)'.'Admission team support needed',
    "Admission team support needed",
    'Referral Status (Referrals)'.'Referral bonus unlocked',
    "Referral bonus unlocked",
    'Referral Status (Referrals)'.'Referral code shared',
    "Referral code shared",
    "Application submitted"
    )

Explanation

  • Switch Function:- The Switch function evaluates an expression (ThisItem.'Referral Status' in this case) and then returns a result depending on the value of that expression. It’s a more streamlined alternative to a series of If statements, often resulting in clearer and more concise code.

  • Expression to Evaluate:- ThisItem.'Referral Status': This expression refers to the ‘Referral Status’ field of the current item (ThisItem) in a collection or data source. In the context of Power Apps, ThisItem typically refers to the current item in a gallery, form, or other data-bound control.

  • Cases in the Switch Function:- The function checks the value of ThisItem.'Referral Status' against several specified cases. Each case consists of a possible value for 'Referral Status', followed by the corresponding result to return if that case matches:
    • If the status is 'Referral Status (Referrals)'.'Referral bonus settled', it returns the text "Referral bonus settled".
    • If the status is 'Referral Status (Referrals)'.'Admission team support needed', it returns "Admission team support needed".
    • If the status is 'Referral Status (Referrals)'.'Referral bonus unlocked', it returns "Referral bonus unlocked".
    • If the status is 'Referral Status (Referrals)'.'Referral code shared', it returns "Referral code shared".
  • Default Case:- The last value in the Switch function ("Application submitted") serves as the default case. If ThisItem.'Referral Status' does not match any of the earlier cases, the function returns "Application submitted".

In summary, this code snippet is used to determine a text description based on the ‘Referral Status’ of the current item in a data set. It’s a typical use case in scenarios where you want to convert status codes or technical terms into more user-friendly, readable text in a UI, such as in a list, gallery, or data table.

Happy #low-code learning

Visit: www.amitpuri.com

Id: Chapter-08-CS00002

Category: Chapter 08

Amit Puri, Advisor and Consultant, Strengthening Digital Experiences, Modernize Cloud Journey with AI-Driven Transformation!

Code Snippet # 8
Chapter-08-CS00008 - Code Snippet # 8
Code Snippet # 2
Chapter-06-CS00002 - Code Snippet # 2
Code Snippet # 10
Chapter-08-CS00010 - Code Snippet # 10