Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

List Collector variable not returning approver in flow designer

SHALIKAS
Tera Guru

I have a list collector variable called application_name which refers to the service table. I want the managed_by person which is in the service table to be the approver. I am writing the below script but it is returning empty values
var approvers =[];

var service= fd_data._1__get_catalog_variables.application_name;

var gr=new GlideRecord('cmdb_ci_service');

if(gr.getValue(service))

{

var m=gr.getValue('managed_by');

approvers.push(m);

}

return "ApprovesAnyU[" +approvers.join(',') + "]";

 

This is returning correct approver if only 1 value is selected in the list collector variable but for more than one value it is returning empty approver.

I also tried using

SHALIKAS_0-1723626210811.png

Still returning empty values

3 REPLIES 3

Mark Manders
Mega Patron

What is the value of your variable when you check the execution details? It looks like you are checking the cmdb_ci_service records based on 1 sys_id, while your variable is a list, not a single record.


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

while I select 1 value in the list collector variable then it is returning one value.

If I select more than one value in list collector variable it returns empty

Does this help:

(function() {
    var approvers = [];
    var serviceNames = fd_data._1__get_catalog_variables.application_name; 

    // Iterate through each selected application in the list
    for (var i = 0; i < serviceNames.length; i++) {
        var serviceName = serviceNames[i];
        var gr = new GlideRecord('cmdb_ci_service');
        if (gr.get('name', serviceName)) { 
            var manager = gr.getValue('managed_by');
            if (manager) {
                approvers.push(manager);
            }
        }
    }
    return "ApprovesAnyU[" + approvers.join(',') + "]";
})();

Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark