- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
‎07-20-2022 06:20 AM
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
Solved! Go to Solution.
- Labels:
 - 
						
							
		
			Scripting and Coding
 
- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
‎07-20-2022 06:27 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
‎07-20-2022 06:25 AM
Hi Cirrus,
You can use switch statements to get rid of multiple if/else statements.
Regards,
Deepankar Mathur
- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
‎07-20-2022 06:27 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
‎07-20-2022 06:58 AM
Perfect, Thanks Ankur
