- 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 09:12 AM
so getDisplayValue() is working and getting the value as New for the variable is_this_for_a_new_or_replacement
can you try this
var itemName = rec.cat_item.name.toString();
is your flow trigger on sc_req_item table? then the above should work
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: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:31 AM
Hi,
getDisplayValue() should work.
I have used this in recent times couple of days back
Regards
Ankud
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:53 AM
Thanks! For some reason, it wasn't working for me in an Orlando instance.
I will retest!
Cheers!