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 ofIf
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"
.
- If the status is
- Default Case:- The last value in the
Switch
function ("Application submitted"
) serves as the default case. IfThisItem.'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
Dr. Amit Puri, Advisor and Consultant, Strengthening Digital Experiences, Modernize Cloud Journey with AI-Driven Transformation!