dipak_thakor
ServiceNow Employee
Options
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
04-01-2022
05:37 AM
As a business outcome you made need to provide a way to view the number of days/hours a request has been open based on the business work schedule.
How do we design this solution using architectural principles, by using the GlideSchedule() API, you can calculate the number of days/hours since the request has been created, based on a schedule . For information on schedules, click here.
So what type of ServiceNow features, can we use to design our solution:
1.Schedule: We need to set up a schedule, based on the business work schedule and excluding any holidays. Schedules are rules that include or exclude time for various actions or tasks. There are many default schedules that are available in the base system.
2.Business Rule: A business rule is a server-side script that runs when a record is displayed, inserted, updated, or deleted, or when a table is queried. We can then write a business rule script that calls the GlideSchedule() API, every time the record is displayed. The GlideSchedule() API, provides methods for performing operations on GlideSchedule objects, such as adding new schedule segments to a schedule, determining if a datetime is within the schedule, or setting the schedule timezone.
In this case we can use the GlideSchedule() API to work out the number of days/hours a request has been open based on the business work schedule i.e.Monday-Friday 8-5 and excluding US Holidays.
Example:
var startDate = new GlideDateTime('2022-03-01 00:00:00');
var endDate = new GlideDateTime('2022-03-05 00:00:00');
var schedule = new GlideSchedule();
schedule.load('090eecae0a0a0b260077e1dfa71da828'); // loads "8-5 weekdays excluding US holidays, OOB schedule
var duration = schedule.duration(startDate, endDate);
gs.info(duration.getDurationValue()); // gets the elapsed time in schedule, e.g.
var endDate = new GlideDateTime('2022-03-05 00:00:00');
var schedule = new GlideSchedule();
schedule.load('090eecae0a0a0b260077e1dfa71da828'); // loads "8-5 weekdays excluding US holidays, OOB schedule
var duration = schedule.duration(startDate, endDate);
gs.info(duration.getDurationValue()); // gets the elapsed time in schedule, e.g.
Output:
1 12:00:00
This denotes 1 day and 12 hours.
3.Field: Now that we have our schedule and our business rules components. We now need to share the result to our users. So they can view the number of days/hours elapsed based on the business schedule. To do this we will be outputting the results of our calculation into a field, displayed on the request record. We also need to ensure that the field is read only. This is to ensure that the calculated value cannot be overridden by the user.
- 2,228 Views
2 Comments
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
