How to get list collector variable selected values

Aishwarya20
Tera Contributor

I have a list collector variable on catalog item and users are selecting multiple values. I want to compare that values with custom table field.

how can I achieve this?

Please suggest me a solution

 

Thanks

10 REPLIES 10

I am just trying in background script but its return a sys id

var gr = new GlideRecord('sc_req_item');
gr.addQuery('number','RITM8055555');
gr.query();

if(gr.next())

{
var variablename = gr.u_assignment_groups.toString(); // here it gives all values comma seperates


var splitthevalues = variablename.split(',');

}


gs.print(splitthevalues);

@Aishwarya20 

you are saying you want to get list collector variable value but you are using u_assignment_groups which is a field

Can you explain clearly what's your actual question and business requirement?

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

My actual requirement is - I want to show other field values on the basis of that values

for example - assignment group is a list collector field and that refers to group table, I want to show related email ids(DL's) on the basis of user select values

@Aishwarya20 

So is the script not working? what's the outcome?

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

Amit Gujarathi
Giga Sage
Giga Sage

HI @Aishwarya20 ,
I trust you are doing great.

 

  1. Identify the catalog item and the custom table field you want to compare the values with.

  2. Create a server-side script in the catalog item's order guide script include or in a business rule. This script will retrieve the selected values from the list collector variable and perform a query on the custom table.

  3. Inside the script, retrieve the selected values from the list collector variable using the getValue() method. This method returns an array of selected values.

  4. Use the retrieved values to construct a query condition to compare with the custom table field. You can use the GlideRecord API to query the custom table and apply the condition.

Here's an example code snippet that demonstrates these steps:

 

// Get the selected values from the list collector variable
var selectedValues = current.variables.myListCollectorVariable.getValue();

// Query the custom table and apply the condition
var gr = new GlideRecord('my_custom_table');
gr.addQuery('my_field', 'IN', selectedValues);
gr.query();

// Iterate through the records matching the condition
while (gr.next()) {
  // Access the fields of the matched records if needed
  var fieldValue = gr.my_field.toString();
  // Do something with the matched records
}

 


Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi