How to write List collector variables in advanced reference and script include

Anish9515
Tera Contributor

Hi  @Ankur Bawiskar 

1. How to pass variable in script include
2.How to write syntax for list collector variables in reference qualifier

3. Based on software product variables in List collect variable software version is populate

4.Backend name for software variable is software_product.

Suresh47_0-1680604128001.pngSuresh47_1-1680604205739.png

Let me know how to write on this

 

5 REPLIES 5

gpaspot13
Kilo Contributor

<div/>List collector variables are a type of variable used in ServiceNow to capture multiple values in a single field. Here's how to write List collector variables in advanced reference and script include:

  1. Advanced reference: In an advanced reference field, you can use the GlideList object to access the values of a list collector variable. Here's an example code snippet:
cssCopy code
var listCollector = current.variables.list_collector_field; // replace "list_collector_field" with your variable name var values = []; for (var i = 0; i < listCollector.size(); i++) { values.push(listCollector.get(i)); }

This code creates an empty array called "values", and then loops through each value in the list collector field, adding it to the array.

  1. Script include: In a script include, you can access the values of a list collector variable using the same GlideList object. Here's an example code snippet:
csharpCopy code
function getValuesFromListCollector(variableName) { var listCollector = new GlideList().get(current, variableName); var values = []; for (var i = 0; i < listCollector.size(); i++) { values.push(listCollector.get(i)); } return values; }

This code defines a function called "getValuesFromListCollector" that takes the name of the list collector variable as a parameter. The function creates a new GlideList object and uses it to get the values of the variable. It then loops through each value in the list collector field, adding it to an array called "values". The function returns the array of values.

By using these code snippets, you can easily access the values of a list collector variable in an advanced reference or script include in ServiceNow.</div>

Ankur Bawiskar
Tera Patron
Tera Patron

@Anish9515 

since you are passing list collector you should query like this

gr.addQuery('u_product_grouping_id', 'IN', input.toString());

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

I'm passing reference variable that is software product 
What about reference qualifier syntax

@Anish9515 
You should add reference qualifier as below-

 

javascript&colon;new scriptIncludeName().functionName(software_product_variable_name);

as per your screenshot-function name is-productVersion()

 

Thanks,

Manjusha Bangale