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

Stefan Reichelt
Tera Guru
Tera Guru

Maybe a silly question (I just briefly looked over the code yet): Why are you using a script instead of the OOB "Lookup Records" action?

Community Alums
Not applicable

Hi @Stefan Reichelt,

Thank you. Maybe I will try this.

Regards

Suman P.

Did you succeed? 🙂

Toderean alexan
Tera Contributor

Hi @Community Alums 

   I recommend you after you have taken your data into variables, make sure that those data are also valid before doing another operation. You can do that by "gs.info()" function and if condition.