Issue with workflow condition based on a list collector variable

Sue143
Tera Expert

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?

 

answer = ifScript();
 
function ifScript() {
    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]))
            return 'yes';

        else

            return 'no';

    }
}
1 ACCEPTED SOLUTION

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.

  

View solution in original post

10 REPLIES 10

Great to hear, happy to help!

 

 

Connect with me https://www.linkedin.com/in/brad-bowman-321b1567/