Getting [object GlideRecord] for some of Input variables in Script Step of Action called from Flow.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2024 12:31 AM - edited 09-28-2024 12:33 AM
Hello ,Please find my code and Output ,could you please help out me where is the error ?
My Code :
Subject: After Action Report, [object GlideRecord] - undefined
Created On: 2024-09-28 07:09:19 - Resolved At: 2024-10-01 07:08:55
INC0010054 with 3D Pinball is broken was entered into ServiceNow by admin for [object GlideRecord]. The Configuration Item affected was undefined. Resolved by: [object GlideRecord] with a Resolution code of undefined. Resolution notes are as follows: undefined
Total time: -2 Days
- Labels:
-
Cost Management (ITSM)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2024 05:31 AM
What's the difference between the fields that worked and the fields that said [object GlideRecord]?
Answer: The fields that worked weren't references.
Open up your background scripts on Dev and do the following
var rotisserieChicken = new GlideRecord('incident');
rotisserieChicken.setLimit(1);
rotisserieChicken.query();
while (rotisserieChicken.next()){
gs.print(rotisserieChicken.caller_id);
}
What does it output? A sys_id right?
But you were EXPECTING it to be "the person". Remember, all reference fields store sys_ids ("use this key to look up in another table and let me borrow all that record's data). In the ServiceNow UI it doesn't show us the sys_id, it shows us the DISPLAY VALUE.
So lets revisit our script....
var rotisserieChicken = new GlideRecord('incident');
rotisserieChicken.setLimit(1);
rotisserieChicken.query();
while (rotisserieChicken.next()){
//adding getDisplayValue()
gs.print(rotisserieChicken.caller_id.getDisplayValue());
}
So all you need to do is put the .getDisplayValue() on any of those parts of your code that are dropping reference fields. Kuddos to you for taking on custom flow actions. BE SURE TO DOCUMENT WHAT YOU BUILT!!