Code Snippet #1
For referral status icons
This code snippet display different icons based on the referral status
Switch(
ThisItem.'Referral Status',
'Referral Status (Referrals)'.'Referral bonus settled',
Icon.Money,
'Referral Status (Referrals)'.'Admission team support needed',
Icon.Support,
'Referral Status (Referrals)'.'Referral bonus unlocked',
Icon.Unlock,
'Referral Status (Referrals)'.'Referral code shared',
Icon.Key,
Icon.LogJournal
)
Explanation
This code snippet uses the Switch
function, which is a way to handle multiple conditional cases. This function is typically used to evaluate an expression and return different results based on the value of that expression.
-
Switch Function:- The
Switch
function evaluates an expression and then returns a result depending on the value of that expression. It works similarly to a series ofIf
statements, but is often more concise and easier to read. -
ThisItem.’Referral Status’:- This
ThisItem.'Referral Status'
expression evaluates referral status.ThisItem
refers to the current item in a collection or data source, particularly when used in a gallery, form, or other data-bound control.'Referral Status'
is a field in the current item. - Cases in the Switch Function:- The
Switch
function then checks the value ofThisItem.'Referral Status'
against several possible values. Each case is a value that'Referral Status'
might have, followed by the result that should be returned if that case matches.- If the status is
'Referral Status (Referrals)'.'Referral bonus settled'
, it returnsIcon.Money
. - If the status is
'Referral Status (Referrals)'.'Admission team support needed'
, it returnsIcon.Support
. - If the status is
'Referral Status (Referrals)'.'Referral bonus unlocked'
, it returnsIcon.Unlock
. - If the status is
'Referral Status (Referrals)'.'Referral code shared'
, it returnsIcon.Key
.
- If the status is
- Default Case:- The last value in the
Switch
function (Icon.LogJournal
) is the default case. IfThisItem.'Referral Status'
does not match any of the specified cases, the function returnsIcon.LogJournal
.
In summary, this code snippet is used to display different icons based on the referral status of the current item in a data set. It’s a concise and effective way to handle multiple conditions, making it easier to manage and read compared to multiple nested If
statements. This is particularly useful in user interface scenarios where you want to visually represent the status of items in a list or gallery.
Happy #low-code learning
Amit Puri, Advisor and Consultant, Strengthening Digital Experiences, Modernize Cloud Journey with AI-Driven Transformation!