Page Composer Expression Builder If/Then/Else Condition
This area explains how to Use the If/Then/Else condition in the Expression Builder of Page Composer.
In this example we will be using the expression to mask the person name only if the following conditions are met:
The user has NOT been assigned the abstract role created in the earlier step
The expenditure item type equals “Professional” which identifies expenditure items containing sensitive hourly rate information for contractors
Where
securityContext.userInRole[‘<Role Name>'] returns a true or false if the role specified has been assigned to the user
row.<attributename> returns the value assigned to the outputText for the row
== is an operator used for comparing values
? : is used for if/then/else
? : is used for if/then/else
Step 1: Edit the Page
You will need the required adminstrator privileges to access the page composer. Once these are assigned to your user open the the required page and from the administrators menu click on the action link 'Edit Pages'.
Step 2: Click on the ‘Select’ tab in the page composer menu.
Step 3: Select the field you want to update and then click on the 'Edit Component' action.
Step 4: Under Component Properties click on the drop down list for value and select Expression Builder.
Step 5: Write the Below Code
Using the above we apply the following logic
IF the role ‘XXX_PJC_VIEW_PERSON_NAME_ABSTRACT’ has been assigned to our user, our user has access THEN we display the value currently assigned to the outputText for the person name.
securityContext.userInRole['XXX_PJC_VIEW_PERSON_NAME_ABSTRACT']==true? row.PersonNameDisplayValue
ELSE the role has NOT been assigned and we proceed to check if the expenditure type equals ‘Professional’. If the outputText value assigned is ‘Professional’ THEN we override the person name with ‘***’
: row.ExpenditureTypeDisplayValue=='Professional'? '***'
ELSE the expenditure type is not equal to ‘Professional’ and there is no need to mask the person name
: row.PersonNameDisplayValue
Below is the full sample expression to achieve this
#{securityContext.userInRole['XXX_PJC_VIEW_PERSON_NAME_ABSTRACT']==true? row.PersonNameDisplayValue : row.ExpenditureTypeDisplayValue=='Professional'? '***' : row.PersonNameDisplayValue}
Comments
Post a Comment