How to store the business hours since the incident was last updated?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2025 02:46 AM
Hi All,
I want to store the business hours in some field since the incident was last updated.
For example if incident was last updated 2 days ago, I want to add that time in business hours & store it in some field.
So, here the field will store the value as (9x2 = 18 hours) .
Any help will be appreciated.
Thanks
Nayan Mule
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2025 02:49 AM
what's your business requirement here?
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
01-20-2025 03:05 AM
Hi @Ankur Bawiskar , if you check my post
I want to run a flow to update incidents based on state conditions & last updated business time. So, I was thinking to add a field to calculate the business hours since last updated incident time.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2025 03:13 AM
you can store this using this logic
1) make before update BR
2) pick the previous updated time from sys_updated_on, get the current date/time
3) subtract both the date/time using schedule and store in that field
something like this
(function executeRule(current, previous /*null when async*/) {
// Define the business hours schedule
var schedule = new GlideSchedule();
schedule.load('your_business_hours_schedule_sys_id'); // Replace with your business hours schedule sys_id
// Calculate the time difference in seconds
var timeDiffInSeconds = gs.dateDiff(previous.sys_updated_on, new GlideDateTime(), true);
// Convert the time difference to business hours
var businessHours = schedule.duration(timeDiffInSeconds) / 3600; // Convert seconds to hours
// Store the business hours in the custom field
current.u_business_hours_since_update = businessHours;
})(current, previous);
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
01-20-2025 05:42 AM
Hi @Ankur Bawiskar , however this didn't work