- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2024 03:19 PM
Hi all,
I am trying to get an yes or no answer on my workflow based on a list collector values, which are reference from a custom table.
What I need to achieve is to identify the values selected in the list collector and based on these values do something like dot walking to get which change group is related to that value in the table.
This is my script, but so far does not return any value, can someone help me and put me in the right direction?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2024 03:06 AM - edited 08-23-2024 10:50 AM
The next step is to temporarily add some log lines to the script so you can see what is happening. It also sounds like this would be better with a more conventional approach - return all of the list collector records, then test each for the condition match. Also, I shouldn't have used 'answer' as a script variable since it is already a part of the if activity.
answer = ifScript();
function ifScript() {
var collector = current.variables.my_variable.toString(); //get variable name from catalog item
workflow.info('collector = ' + collector); //verify the variable was retrieved
var gr = new GlideRecord('my_custom_table'); //access the custom table that store the values from List collector
gr.addQuery('sys_id', 'IN', collector);
gr.query();
while (gr.next()) {
workflow.info('Record found ' + gr.sys_id + ' Group = ' + gr.u_change_group); //change this to a more descriptive field on the custom table
if (gr.getValue('u_change_group') == 'dcfb023edb4d1340439d14a05b9619c5') { //define the change group with sys_ID
workflow.info('Group matched');
return 'yes'; //stop running the script when the first group match is found
}
}
workflow.info('No list collector record had a matching group');
return 'no'; //if no groups matched, take the No path
}
Be sure to test this workflow change with a newly-submitted record. You can view these logs on the Log tab while viewing the context from the Related Link at the bottom of the RITM.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2024 03:44 PM
Try this, if you know what specific sys_id you are looking for you can just use indexOf.
answer = ifScript();
function ifScript() {
var collector = current.variables.my_variable.toString(); //get variable name from catalog item
var list = collector.split(",");
if (list.indexOf('dcfb023edb4d1340439d14a05b9619c5') > -1)
return 'yes';
else
return 'no';
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2024 07:06 PM
Hi Brian, thank you for your response but this is not enough to solve my issue, the list collector is getting the values from a custom table.
The sys_id is not of the value available in the list collector but of the change group associated with the value of the list collector.
I need to get the value from the list collector and access it on the custom table to find out if the change group assigned is the one of the sys_id.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2024 07:20 AM
If the list collector is pointing to a custom table then the only thing you can select is from that custom table. If the custom table has change group in it and that is all you can select then the all the sys_id in the list collector will be from a change group.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2024 03:52 PM
Hello,
The first issue is with the addQuery - you can either use
gr.addQuery('u_change_group', 'dcfb023edb4d1340439d14a05b9619c5'); //define the change group with sys_ID
or
gr.addEncodedQuery('u_change_group=dcfb023edb4d1340439d14a05b9619c5'); //define the change group with sys_ID
Secondly, there is likely a logic problem as the script will end with the first list collector entry. It's a little unclear what you're trying to do with the list collector values, but if you are wanting to loop through all of the list collector entries, then return the value if ANY of them match the change group, it would look something like this:
answer = ifScript();
function ifScript() {
var answer = 'no';
var collector = current.variables.my_variable.toString(); //get variable name from catalog item
var list = collector.split(",");
for (var i = 0; i < list.length; i++) {
var gr = new GlideRecord('my_custom_table'); //access the custom table that store the values from List collector
gr.addQuery('u_change_group', 'dcfb023edb4d1340439d14a05b9619c5'); //define the change group with sys_ID
if (gr.get(list[i]))
answer = 'yes';
}
return answer;
}