IF Inside an IF with ELSE

🎲 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:

  1. It checks if the first element (index 0) of the logType array is equal to one of the three specified values.
  2. If one of the specified logType values matches and both approved and chargeableExpense are true, it sets the quantity to true.
  3. Else, it sets the quantity to false.
  4. If none of the logType values match, the last ELSE block adds an action to make the quantity field not mandatory by setting it false.
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?

If you require assistance or encounter any issues, please don't hesitate to contact us for further support.