Write a script to calculate the time taken from new to in progress state of incident and display
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-22-2023 02:15 AM
Write a script to calculate the time taken from new to in progress state of incident and display on form field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-22-2023 04:59 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-22-2023 05:17 AM
hi
calculate the difference time between created and update time then I have to display the time in Time taken field .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-22-2023 05:09 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-22-2023 09:32 AM
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