Validation on list collector values
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2018 12:01 AM
Hi All,
I have a valraible on the form of type "list collector" . say for example we have 4 values in that
A,B, C and D.
I want to write a script in the workflow of that SR to check if users has selected value "A".
I have done any validation like this, seeking for any help or assistance on the same.
Regards,
Jyoti
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2018 12:33 AM
Hi,
Here is the example how you will use in workflow
https://community.servicenow.com/community?id=community_question&sys_id=0fa64765db1cdbc01dcaf3231f961900
Mark my ANSWERR as CORRECT and HELPFUL if it helped

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2018 12:35 AM
Hi,
List collector is type reference.
You can get the selected value of list collector (lets say variable name is 'field1') as var selectedVariable = current.variable.field1;.
Now, write a logic as per your requirement. You can use
var arrayUtil = new ArrayUtil();
arrayUtil.contains(selectedVariable, "value you want to check"); // this will return true if value exist else fals.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2018 10:49 PM
var roles = current.variables.normal_roles;
gs.log('mydoc------roles test');
var flag ;
var arrayUtil = new ArrayUtil();
gs.log('mydoc------array'+arrayUtil);
if(arrayUtil.contains(roles, "Other"))
{
flag = 1;
gs.log('mydoc------flag1');
}
else
{
flag = 0;
gs.log('mydoc------flag0');
}
This is returning me array[object, object] but not the actual value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2018 12:52 AM
Hi Jyoti,
The list collector delivers its selections (what is moved to the right list collector box) into an array. To access the information you would need to parse through the array. I've included an example that I use in a workflow below, also including one where I set it to a string and comma separated values.
current.variables.list_collector_name //will give an array
current.variables.list_collector_name.toString(); //will give string with comma separated values