Calculate Incident on hold duration
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2021 02:24 PM
The requirement is to calculate the on hold duration of an incident. Whenever an incident state changes from on hold , it should populate the total on hold time in a new field 'On hold Clock'.
The code I am using reflects first on hold time when my incident goes on hold for second time , but its not working for first time, tried putting a delay but did not work.
Before BR
Table: incident, Condition: state changes from On hold
gs.sleep(8000);
var timems =0;
var tm = 0;
var gr=new GlideRecord('metric_instance');
gr.addQuery('id',current.sys_id);
gr.addQuery('value','On Hold');
gr.query();
while(gr.next()){
tm = gr.duration.dateNumericValue();
timems += tm;
}
current.u_on_hold_clock.setDateNumericValue(timems);
Please suggest the modification to make it work in first time itself.
Thanks
Pooja
- Labels:
-
Incident Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2021 04:03 PM
Hi, using any form of sleep() in your code is not advisable, as it can (and will) have a detrimental impact on your instance performance.
It would be a better utilization of system resources to either
Add another field to your incident of type date\time, EG u_paused_time
Then in a beforeBR, if the incident is placed on hold set u_paused_time with the paused date\time.
if the incident is taken of hold, calculate the hold time (current time – u_paused_time) and add this value to your existing ‘On hold Clock’ field;
Then reset u_paused_time to '', NULL or epoch (depending on your preference).
Another other option would be an OLA\SLA that tracks hold time and an afterBR on task_sla which would update incident ‘On hold Clock’ with the pause time.
The additional incident update this solution requires would still be much better for your operational environment than locking a worker with sleep().
As a bouns the OLA\SLA will manage schedules for you without any additional coding.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2021 12:23 AM
Thanks Tony,
Add another field to your incident of type date\time, EG u_paused_time
Then in a beforeBR, if the incident is placed on hold set u_paused_time with the paused date\time.
if the incident is taken of hold, calculate the hold time (current time – u_paused_time) and add this value to your existing ‘On hold Clock’ field;
This logic worked.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2023 03:49 AM
Hello @Pooja68
Would you please share the final code here? I have also similar requirement
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2021 01:21 AM
Please join the below SERVCENOW INDIA FORUM @Telegram App
This group is focused on growing Servicenow skills/Learning/Quries/Meetups/Certifications/dumps/courses/interview/MockTest etc..
☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....