- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-20-2020 08:18 AM
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;
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-20-2020 08:24 AM
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-20-2020 08:24 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-20-2020 08:43 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-20-2020 09:06 AM
Does this work:
rec.getDisplayValue('cat_item');
Or, you could use the data pills:
fd_data.trigger.request_item.cat_item.name;
Tim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-21-2020 12:39 AM
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;