Catalog Item Set Value on Incident

Dallas Fanchier
Tera Expert

I currently am working on a catalog item.  I have a variable that uses a list collector for the computer table.  On the form you can select multiple computers by name.  In my workflow I create an incident and set the description to list the list collector results.  It returns the sysid and not the computer name.  I checked dictionary to make sure I wasn't crazy and the name field is set to name.  I was looking at functions on the variable in the flow designer but not sure how I can fix this.  When I had it set to reference where only one record can be selected it worked properly but when I changed it to multi select I started having this issue.

1 ACCEPTED SOLUTION

Hi @Dallas Fanchier 

 

Give this a try

var comp = fd_data._1__get_catalog_variables.server.toString();
var str = '';

if (comp != '') {

var compList = comp.split(',');



for (i = 0; i < compList.length; i++) {


var grComp = new GlideRecord('cmdb_ci_computer');

grComp.addQuery('sys_id', compList[i]);

grComp.query();


while (grComp.next()) {

str += grComp.name + ', ';

}}}
return str;

 

 

View solution in original post

10 REPLIES 10

Manmohan K
Tera Sage

Hi @Dallas Fanchier 

 

List collector stores values in the form of  sys_id and not display name for selected items in the field

Please use below script in workflow to set description with names of computers (replace list collector field name in script in first line)

 

var comp = current.variables.YOUR_FIELD_NAME.toString();

if (comp != '') {


    var compList = comp.split(',');

    var str = '';

    for (i = 0; i < compList.length; i++) {


        var grComp = new GlideRecord('cmdb_ci_computer');

        grComp.addQuery('sys_id', compList[i]);

        grComp.query();


        while (grComp.next()) {

            str += grComp.name + ', ';

        }

    }

    current.short_description = str;

}

 

I put the following in the description script but nothing populates.  It is empty.  The field on the item is called server.  I changed the bottom line to description and not short_description.  What am I doing wrong?

 

var comp = current.variables.server.toString();

if (comp != '') {


var compList = comp.split(',');

var str = '';

for (i = 0; i < compList.length; i++) {


var grComp = new GlideRecord('cmdb_ci_computer');

grComp.addQuery('sys_id', compList[i]);

grComp.query();


while (grComp.next()) {

str += grComp.name + ', ';

}

}

current.description = str;

}
 
 
DallasFanchier_0-1686071264557.png

 

Manmohan K
Tera Sage

Hi @Dallas Fanchier 

 

You would have to change the script to get it to work in flow. You might have to adjust first line so that dot walking is correct for the flow

 

var comp = fd_data.trigger.current.variables.server.toString();
var str = '';

if (comp != '') {

var compList = comp.split(',');



for (i = 0; i < compList.length; i++) {


var grComp = new GlideRecord('cmdb_ci_computer');

grComp.addQuery('sys_id', compList[i]);

grComp.query();


while (grComp.next()) {

str += grComp.name + ', ';

}}}
return str;

 

 

Treat me as if I don't know scripting.  I don't really.  What should the script be knowing my field name is server and I am referencing the computer table.  I ran the last script but get an error.

Error: attempting to use undefined input='current' from Catalog item