How to Populate the select box label name which is selected in the service request using workflow

Community Alums
Not applicable

So in the short description of the RITM i am trying to populate the values which have been selected but unable to populate as shown in attached screenshot.

 

Used the below script to populate the value but was not bale to populate the Short Description.

PRITHVIRAMESH_0-1690552233562.png

 

// Ensure that current and current.cat_item are defined before proceeding
if (current && current.cat_item) {
    var add = current.u_add;
    var modify = current.u_mod;
    var remove = current.u_rem;
    var dele = current.u_del;
    var selectedVariable = [];

    if (add === true) {
        selectedVariable.push('u_add');
    }

    if (modify === true) {
        selectedVariable.push('u_mod');
    }

    if (remove === true) {
        selectedVariable.push('u_rem');
    }

    if (dele === true) {
        selectedVariable.push('u_del');
    }

    // Concatenate the selected variables and update short_description
    current.short_description = current.cat_item.name + " + update: " + selectedVariable.join(', ');
} else {
    // Handle the case when current or current.cat_item is undefined
    current.short_description = "Error: cat_item or current is undefined.";
}
9 REPLIES 9

Elijah Aromola
Mega Sage

 

If you're going to be doing strict equality comparisons (===) you need to verify the types are matching. I assume from this script that those variables aren't typeof boolean, they are strings. Change each if statement to validate against a string 'true'. 

Community Alums
Not applicable

Thanks for replying back, so I checked by replicating the same thing as you instructed, but it didn't work.

Can you provide what code you attempted to run? Can you also try changing your comparisons to ==?

Community Alums
Not applicable
// Ensure that current and current.cat_item are defined before proceeding
if (current && current.cat_item) {
    var add = current.u_add;
    var modify = current.u_mod;
    var remove = current.u_rem;
    var dele = current.u_del;
    var selectedVariable = [];

    if (add == 'true') {
        selectedVariable.push('u_add');
    }

    if (modify == 'true') {
        selectedVariable.push('u_mod');
    }

    if (remove == 'true') {
        selectedVariable.push('u_rem');
    }

    if (dele == 'true') {
        selectedVariable.push('u_del');
    }

    // Concatenate the selected variables and update short_description
    current.short_description = current.cat_item.name + " + update: " + selectedVariable.join(', ');
} else {
    // Handle the case when current or current.cat_item is undefined
    current.short_description = "Error: cat_item or current is undefined.";
}

Here is the code