We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

Calculate Incident on hold duration

Pooja68
Tera Contributor

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

6 REPLIES 6

Andrea Lorenzo
Tera Contributor

Hello, 

 

Would you mind to share the script used to achieve this goal? I am trying to calculate the On Hold Duration but I am unable to figure on how to do the script.


Thank you,

 

Andrea Lorenzo Gambadoro

Mayuri1711
Tera Contributor

Hi @Pooja68,

Could you please share the final code here? I have similar requirement