How to add Multi Select Variable in Workflow If condition

Ankita Gupte
Kilo Sage

Hello Experts,

I need help with below two scripts in servicenow

1. I have a multi select variable on catalog item form which shows below two values

find_real_file.png

So whenever the "Admin Access" i.e. var_mafv_admin_access_win value is Yes it should trigger approval to a user.

2. Also there is another Multi select variable set i.e. vs_mafv_vitc_new_server_nw_ports whenever any row is populated in this variable set it should trigger further approval

find_real_file.png

How do I get this value in If logic of workflow?

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Ankita Gupte 

update as this and also you should set yes and no and not Yes and No

answer = ifScript();

function ifScript() {
    var ans = 'No';
    var var_array = current.variables.var_mafv_win_user_list;
    var rowCount = var_array.getRowCount();
    for (var i = 0; i < rowCount; i++) {
        var row = var_array.getRow(i);
        if (row.var_mafv_admin_access_win == "Yes") {
            ans = 'yes';
            break;
        }else {
            ans = 'no';
        }
    }
    return ans;
}

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

4 REPLIES 4

OlaN
Giga Sage
Giga Sage

Hi,

Have a look at this article to get some pointer on how to script a MRVS.

I have written below script.

answer = ifScript();

function ifScript() {
    var ans = 'No';
    var var_array = current.variables.var_mafv_win_user_list;
    workflow.info('value of MRVS=' + var_array);
    var rowCount = var_array.getRowCount();
    for (var i = 0; i < rowCount; i++) {
        var row = var_array.getRow(i);
        //         if ((row.var_ad_security_group != "None") || (row.var_ad_security_group != "none") || (row.var_ad_security_group != "No_Specific_Report_Access_is_Required")) {
        //         if ((row.var_ad_security_group != "None")) {

        if (row.var_mafv_admin_access_win == "Yes") {
            ans = 'Yes';

        }else {
            ans = 'No';
        }
    }
    return ans;
}

 

If single row is selected and admin value is yes or no the approval works fine.

But if multiple values are selected and only 1 value is Yes then also it should trigger approval.

find_real_file.png

For above condition it is skipping the approval is any  of the value in No.

 

Ankur Bawiskar
Tera Patron
Tera Patron

@Ankita Gupte 

update as this and also you should set yes and no and not Yes and No

answer = ifScript();

function ifScript() {
    var ans = 'No';
    var var_array = current.variables.var_mafv_win_user_list;
    var rowCount = var_array.getRowCount();
    for (var i = 0; i < rowCount; i++) {
        var row = var_array.getRow(i);
        if (row.var_mafv_admin_access_win == "Yes") {
            ans = 'yes';
            break;
        }else {
            ans = 'no';
        }
    }
    return ans;
}

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Thank You very much Ankur.