Validation on list collector values

jyoti29208
Giga Expert

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

4 REPLIES 4

Ct111
Giga Sage

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

rahulpandey
Kilo Sage

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.

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.

Rupesh Pulamar1
Kilo Expert

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