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
Use metric definitions that provides this information out of box or you can configure new definition and system will provide the details. There is no need to create it via Flow Designer.
Refer below articles,
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0751559
If this helped to answer your query, please mark it helpful & accept the solution.
Thanks,
Bhuvan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Did you get a chance to review this ?
If my response helped to answer your query, please mark it helpful & accept the solution.
Thanks,
Bhuvan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Thanks for marking the post as helpful.
As per community guidelines, you can accept more than one answer as accepted solution. If my response helped to answer your query, please mark it helpful & accept the solution.
Thanks,
Bhuvan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Fix your script:
javascriptvar created = new GlideDateTime(current.sys_created_on);
var assigned = new GlideDateTime(current.u_first_assignment_change);
var duration = GlideDateTime.subtract(created, assigned);
current.u_time_until_first_assigned = duration.getDurationValue();
Issues in original:
Used gs.nowDateTime() instead of current.u_first_assignment_change
Wrong subtraction order (created - now = negative)