Calculate Time differences
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-19-2023 09:15 PM
Hi All, we have a request like ,
1.need to capture time difference between promoted on (date and time field) and current date and time untill restoration time(date and time) is empty and need to push this output to Time elapsed field(string field).
2.if Restoration is set the Time elapsed need to calculate between promoted time minus restoration time.
Could you pls help me with how to achieve this
When to run before BR updated, major incident state is accepted.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-19-2023 10:17 PM
here is the sample script for calculating the time difference. you can add this logic in your BR script
var plannedDatetime = new GlideDateTime(current.getValue('start_date'));
var actualDatetime = new GlideDateTime(current.getValue('work_start'));
var dur = new GlideDuration();
dur = GlideDateTime.subtract(plannedDatetime, actualDatetime); //the difference between
var hour = dur.getByFormat('HH'); //get hour part
var mins = dur.getByFormat('mm'); //get mins
var day = dur.getDayPart();
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-25-2023 07:51 PM
Thank you for marking my response as helpful.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-23-2023 01:21 AM
@Vijaykumar K This time difference between your promoted date and current date will be updated only when the major incident is modified. If your expectation is to have the updated time always,
for example today you update the major incident and the time difference will be exactly calculated and updated, but tomorrow when you look at the incident the difference will still be the same like yesterday and will not be automatically modified while using a BR.
Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-23-2023 08:08 AM
@Arun_S1 is it feasible to get current time always rather then update on Major incident update .?
Promoted to restoration is working as expected.