- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
7 hours ago
What is wrong in below script?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
7 hours ago
try this
var schedule = new GlideSchedule(inputs.schedule_sys_id);
var start = new GlideDateTime(inputs.starting_date);
var end = new GlideDateTime(inputs.ending_date);
var dur = schedule.duration(start, end);
outputs.duration = new GlideDuration(dur);
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
7 hours ago
Hi @Sathwik1
schedule.duration() returns a GlideDuration object. Could you confirm where this script is running (Flow Designer Action, Script Include, Business Rule, etc.)?
Also, when you say the backend field is a Duration field, are you writing outputs.duration directly to that field, or is there another step that performs the update?
The error "return type is not valid" suggests the value being returned isn't in the format the consumer expects, rather than an issue with the duration calculation itself.
Hope it helps,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
7 hours ago
schedule.duration() returns a GlideDuration object, which Flow Designer cannot store directly.
Return a string instead:
var duration = schedule.duration(start, end); outputs.duration = duration.getValue();
Configure the output as String. If you only need a readable value, use:
outputs.duration = duration.getDurationValue();
Thank you,
Vikram Karety,
Octigo Solutions INC
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
7 hours ago
try this
var schedule = new GlideSchedule(inputs.schedule_sys_id);
var start = new GlideDateTime(inputs.starting_date);
var end = new GlideDateTime(inputs.ending_date);
var dur = schedule.duration(start, end);
outputs.duration = new GlideDuration(dur);
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
6 hours ago
Still same error "Invalid return type encountered" @Ankur Bawiskar