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.

flow designer script issue

Community Alums
Not applicable

Hi,

I have written some code to get the list of IT Managers of the servers. I am not getting any output. Kindly help.

 

/*
**Access Flow/Action data using the fd_data object. Script must return a value. 
**Order number is offset by +1 in Error Handling Section.
**Available options display upon pressing "." after fd_data
**example: var shortDesc = fd_data.trigger.current.short_description;
**return shortDesc
*/
var action = fd_data._1__get_catalog_variables.action;
var requested_for = fd_data._1__get_catalog_variables.requested_for_user.sys_id;
var servers_string = fd_data._1__get_catalog_variables.server_s;
var servers_arr = servers_string.split(","); //array
var servers_name_arr = [];
for(var i = 0;i<=servers_arr.length;i++)
{
var gr = new GlideRecord('cmdb_ci_computer');
gr.addQuery('sys_id',servers_arr[i]);
gr.query();
if(gr.managed_by != " "){
while(gr.next())
{
    if(gr.managed_by != requested_for){
      servers_name_arr.push(gr.managed_by.name.toString());
    }

}
}
}
var stringNames = servers_name_arr.toString();
var msg = "Next step: Your request requires approval from IT Manager(s) - " + stringNames;
return msg;

 

servers.png

 

se.pngman.png

 

Regards

Suman P.

5 REPLIES 5

Nootan Bhat
Kilo Sage

Hi @Community Alums 

Your if condition if(gr.managed_by != " ") should be inside the while loop. Without actually moving to next record object you cant really fetch the managed_by value.

 

 

Please mark my response as accepted solution if it was helpful.

 

Thanks

Nootan