- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2014 09:33 AM
Is there a way to set a list collector mandatory for different conditions? I am trying to make it mandatory for a list collector to have at least 2 values selected. I need to do this onChange with a Client Script. I am not familiar with how list collector "answers" or "values" (on the right hand side) are stored so I'm not sure where to start with my script. I know this should be an if statement for when a variable is changed, but I'm not sure what the body should be. Thank you in advance.
Solved! Go to Solution.
- Labels:
-
Service Mapping
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2014 11:09 AM
So here is a script that checks a field called u_analyst_name to see how many people were selected in the list collector. This just alerts for the test scenarios but you should be able to change that. You might want to change it to an on submit script that pops up an error message if there are less then 2 people and aborts the update. I think the set mandatory property only cares if there is one or more values in the list.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var string = g_form.getValue('u_analyst_name');
var array = string.split(",");
if(array.length>1){
alert("less then 2");
}
else{
alert("2 or more");
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2014 10:38 AM
Hi Angela,
I hope this will article from SN guru will be useful
http://www.servicenowguru.com/scripting/client-scripts-scripting/move-list-collector-options/
Thanks,
Pradeep Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2014 10:47 AM
The only data stored in the list collector variable is a comma separated list of the sys_ids of the chosen records. The options that weren't chosen aren't stored anywhere.
That said, client scripts can change the filter of the slush bucket so you only show certain options under specific conditions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2014 11:09 AM
So here is a script that checks a field called u_analyst_name to see how many people were selected in the list collector. This just alerts for the test scenarios but you should be able to change that. You might want to change it to an on submit script that pops up an error message if there are less then 2 people and aborts the update. I think the set mandatory property only cares if there is one or more values in the list.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var string = g_form.getValue('u_analyst_name');
var array = string.split(",");
if(array.length>1){
alert("less then 2");
}
else{
alert("2 or more");
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2014 11:13 AM
I think this can be done through an Before Insert/Update BR.
Condition: previous.field_name.changes() && current.field_name == 'Your New Value'// sysid in case of Reference
Script:-
var list = current.watch_list.toString();
var array = list.split(",");
var ln = array.length;
if(ln<2)
{
gs.addErrorMessage('Your Message');
current.setAbortAction(true);
}
Thanks,
Subhajit