Use Flow Designer to calculate duration between two times?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
I've been asked to find a way to:
1. Record the time an assignment group first changes on an incident
2. Calculate the difference between that time and the time the incident was created
To do this, I tried the following:
1. Added field u_first_assignment_change (time/date type)
2. Added field u_time_until_first_assigned (duration type)
3. I built a workflow to run once when Incident is updated and assignment group changes
4. The first step updates the incident record so u_first_assignment_change=Trigger->Record Updated->Run Start Date/Time
1-4 is all working successfully
But then I try
5. Add a second step to update the incident record, field Time Until Assigned with script:
var gdt1 = new GlideDateTime(current.sys_created_on.getDisplayValue());
var gdt2 = new GlideDateTime(gs.nowDateTime());
var dur = GlideDateTime.subtract(gdt1, gdt2); //the difference between gdt1 and gdt2
var dur1= new GlideDuration();
dur1.setValue(dur.getValue());
current.u_time_until_first_assigned=dur1.getDurationValue();
This isn't working. It isn't adding anything to u_time_until_first_assigned, which stays blank.
Can anyone see what I'm doing wrong?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
@JP-ODU - you are doing it wrongly
to get date fields you need to use fd_data and dot walk till the you get your field
refer felow:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
update your script as this
var gdt1 = new GlideDateTime(current.sys_created_on.getDisplayValue());
var gdt2 = new GlideDateTime(gs.nowDateTime());
var dur = GlideDateTime.subtract(gdt1, gdt2); //the difference between gdt1 and gdt2
current.u_time_until_first_assigned.setDateNumericValue(dur.getNumericValue());
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Thank you for marking my response as helpful.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader