Write a script to calculate the time taken from new to in progress state of incident and display

Sharmila Krishn
Tera Contributor

Write a script to calculate the time taken from new to in progress state of incident and display on form field.

5 REPLIES 5

Hari Prasath
Tera Guru

Hi @Sharmila Krishn ,

 

This article might help you somewhere https://www.servicenow.com/community/developer-forum/how-to-get-the-time-difference-between-two-date... .

 

Please mark the answer as helpful, if you helped you accordingly.

 

Thanks,

Hari

hi

calculate the difference time between created and update time then I have to display the time in Time taken field .

SharmilaKrishn_1-1679487338372.png

 

 

Anurag Tripathi
Mega Patron
Mega Patron

The best way to do it would be create Metrics -> Read more here -> Metrics (servicenow.com)

Alternatively ( assuming the incident record is created in New state) you can create a BR that will run when the state changes to in progress and calculate the difference and stores it in a new custom field.

-Anurag

Hari Prasath
Tera Guru

@Sharmila Krishn 

 

Try the below script, if you need the time difference in a day, you can use that day variable, else skip that part.

 

var createdTime = created_field_backendname.getDisplayValue();
var updatedTime = updated_field_backendname.getDisplayValue();
var timeDifference = gs.dateDiff(createdTime, updatedTime);
var day = timeDifference.getDay();
var day =parseInt(timeDifference);

 

Please make the answer as helpful, if helped you accordingly.

 

Thanks,

Hari