How to get list collector variable selected values
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2023 01:55 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2023 03:08 AM - edited 06-16-2023 03:09 AM
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2023 03:52 AM
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?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2023 02:27 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2023 03:05 AM
So is the script not working? what's the outcome?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2023 03:26 AM
HI @Aishwarya20 ,
I trust you are doing great.
Identify the catalog item and the custom table field you want to compare the values with.
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.
Inside the script, retrieve the selected values from the list collector variable using the getValue() method. This method returns an array of selected values.
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