Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

How to check for multiple selections in a list collector

Cirrus
Kilo Sage

Hopefully my last question on this for a while. Thanks for all your community help to get me to this point.

In my order guide, I need to check the values selected in my list collector variable, and if certain values are selected then the value of a yes/no variable is set to Yes. I have the following, which works ok for the value selected.

function onSubmit() {
    var gr = g_form.getValue('catalog_list'); //  getting the List Collector Variable value
    var ar = gr.split(','); 
    if(ar.indexOf("55d3db6a1b105914ce1564a2b24bcb32") > -1){ // used sys_id of selected record
        g_form.setValue('needs_approval', 'Yes');    
        return true;
    }}

My question is how to query multiple sys_ids on the highlighted line. I suspect a load of if/else statements is not the most efficient (or professional!!) scripting technique

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron

Hi,

something like this

function onSubmit() {
    var gr = g_form.getValue('catalog_list'); //  getting the List Collector Variable value
    var ar = gr.split(','); 
    if(ar.indexOf("55d3db6a1b105914ce1564a2b24bcb32") > -1 || ar.indexOf("sysId2") > -1 || ar.indexOf("sysId3") > -1){ // used sys_id of selected record
        g_form.setValue('needs_approval', 'Yes');    
        return true;
    }
}

Regards
Ankur

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

View solution in original post

3 REPLIES 3

dmathur09
Kilo Sage

Hi Cirrus,

You can use switch statements to get rid of multiple if/else statements.

Regards,

Deepankar Mathur

Ankur Bawiskar
Tera Patron

Hi,

something like this

function onSubmit() {
    var gr = g_form.getValue('catalog_list'); //  getting the List Collector Variable value
    var ar = gr.split(','); 
    if(ar.indexOf("55d3db6a1b105914ce1564a2b24bcb32") > -1 || ar.indexOf("sysId2") > -1 || ar.indexOf("sysId3") > -1){ // used sys_id of selected record
        g_form.setValue('needs_approval', 'Yes');    
        return true;
    }
}

Regards
Ankur

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

Perfect, Thanks Ankur