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:35 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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2024 02:39 AM
Hi @shubhamsriv
Try Below code
try {
var startDate = new GlideDateTime(inputs.created_on);
var endDate = new GlideDateTime(inputs.resolved_at);
var duration = GlideDateTime.subtract(endDate, startDate);
var calcDiff = duration.getDaysPart();
var assignedToName = inputs.assigned_to ? inputs.assigned_to.getDisplayValue() : "N/A";
var callerIdName = inputs.caller_id ? inputs.caller_id.getDisplayValue() : "N/A";
var resolvedByName = inputs.resolved_by ? inputs.resolved_by.getDisplayValue() : "N/A";
var report = "After Action Report\n" +
"Subject: After Action Report, " + assignedToName + " - " + inputs.assignment_group + "\n" +
"Created On: " + inputs.created_on + " - Resolved At: " + inputs.resolved_at + "\n\n" +
inputs.number + " with " + inputs.short_description + " was entered into ServiceNow by " +
inputs.created_by + " for " + callerIdName + ". " +
"The Configuration Item affected was " + (inputs.cmdb_ci ? inputs.cmdb_ci.getDisplayValue() : "N/A") + ". " +
"Resolved by: " + resolvedByName + " with a Resolution code of " + inputs.close_code + ". " +
"Resolution notes are as follows: " + (inputs.close_notes || "N/A") + "\n\n" +
"Total time: " + calcDiff + " Days";
outputs.payload = report;
} catch (error) {
outputs.payload = "Error: " + error.message;
}
Please mark this response as Correct and Helpful if it helps you can mark more that one reply as accepted solution
Thanks
Eshwar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2024 03:02 AM
@shubhamsriv Please try the following and see if it works for you.
(function execute(inputs, outputs) {
// Create GlideDateTime objects for the start and end dates
var startDate = new GlideDateTime(inputs.created_on);
var endDate = new GlideDateTime(inputs.resolved_at);
// Calculate the difference in days
var calcDiff = GlideDateTime.subtract(endDate, startDate).getRoundedDayPart();
// Construct the report string
var report = "After Action Report\n" +
"Subject: After Action Report, " + inputs.assigned_to.name + " - " + inputs.assignment_group.name + "\n" +
"Created On: " + inputs.created_on + " - Resolved At: " + inputs.resolved_at + "\n\n" +
inputs.number + " with " + inputs.short_description + " was entered into ServiceNow by " +
inputs.created_by + " for " + inputs.caller_id.name + ". " +
"The Configuration Item affected was " + inputs.cmdb_ci + ". " +
"Resolved by: " + inputs.resolved_by.name + " with a Resolution code of " + inputs.close_code + ". " +
"Resolution notes are as follows: " + inputs.close_notes + "\n\n" +
"Total time: " + calcDiff + " Days";
// Set the output payload
outputs.payload = report;
})(inputs, outputs);