🎲 Use multiple IF conditions with ELSE.
1. Overview
This Interaction allows for the execution of multiple IF blocks along with ELSE. It allows for different actions to be taken based on multiple IF and ELSE conditions. It is important to be very careful about the position of the ELSE block.
2. Example
This example shows how to use multiple IF blocks along with ELSE conditions. This is how it works:
- It checks if the first element (index 0) of the
logTypearray is equal to one of the three specified values. - If one of the specified
logTypevalues matches and bothapprovedandchargeableExpensearetrue, it sets thequantitytotrue. - Else, it sets the
quantitytofalse. - If none of the
logTypevalues match, the last ELSE block adds an action to make thequantityfield not mandatory by setting itfalse.
async function handler(clev) {
let actions = [];
let approved = clev.getValue("approved");
let chargeableExpense = clev.getValue("chargeable-expense");
let logType = clev.getValue("log-type");
if (
logType[0] === "289365" ||
logType[0] === "289364" ||
logType[0] === "289366"
) {
if (approved === true && chargeableExpense === true) {
actions.push(clev.setFieldMandatory("quantity", true));
} else {
actions.push(clev.setFieldMandatory("quantity", false));
}
} else {
actions.push(clev.setFieldMandatory("quantity", false));
}
return clev.mergeAll(actions);
}📌 Need Help?
