Populate request with cat item name in flow designer

Wasdom_Kung
Tera Guru

Hi,

I currently have a script that auto-populates the description fields on a request depending on what is selected in multiple items - to make this more dynamic, I want to use one flow for multiple items, and use the existing script to update the request field with the relevant item chosen.

I've tried multiple ways of retrieving the catalog item name field but can't get it to work - this is my current script below.

The variable itemName is supposed to have the catalog item name value passed for display.

Hopefully someone can help. 

 

var ritmSysId = fd_data.trigger.request_item.sys_id;

var rec = new GlideRecord('sc_req_item'); 

rec.get(ritmSysId);

var variableDisplayValue = rec.variables.is_this_for_a_new_or_replacement.getDisplayValue();
var itemName = rec.cat_item.name();

return 'Equipment Request - Telecoms: ' + variableDisplayValue + ' ' + itemName;
1 ACCEPTED SOLUTION

Community Alums
Not applicable

In my experience so far with Flow, you can't use 'getValue()' and 'getDisplayValue()' in scripts. You can dot-walk right to the element you need. Also, 'name()' is not a method, so remove the '()':

var variableDisplayValue = rec.variables.is_this_for_a_new_or_replacement;
var itemName = rec.cat_item.name;

 

Try that. Hope that helps!

View solution in original post

8 REPLIES 8

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

use this

var ritmSysId = fd_data.trigger.current.sys_id;

var rec = new GlideRecord('sc_req_item'); 

rec.get(ritmSysId);

var variableDisplayValue = rec.variables.is_this_for_a_new_or_replacement.getDisplayValue();
var itemName = rec.cat_item.getDisplayValue();

return 'Equipment Request - Telecoms: ' + variableDisplayValue + ' ' + itemName;

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

The variable is returning as undefined when I try this for itemName

find_real_file.png

Community Alums
Not applicable

Does this work:

rec.getDisplayValue('cat_item');

Or, you could use the data pills:

fd_data.trigger.request_item.cat_item.name;

 

Tim

I tried using the data pills but this would only work outside of the script - there was no way of me getting the display value for new or replacement so it would be lower case. It worked but not as I wanted.

I managed to get it working with the following:

var ritmSysId = fd_data.trigger.request_item.sys_id;

var rec = new GlideRecord('sc_req_item'); 

rec.get(ritmSysId);

var variableDisplayValue = rec.variables.is_this_for_a_new_or_replacement.getDisplayValue();
var itemName = rec.cat_item.name;

return 'Equipment Request - Telecoms: ' + variableDisplayValue + ' ' + itemName;