how to add breach time on task_sla table based on schedule and start time
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-20-2023 11:56 PM - edited ‎06-21-2023 01:43 AM
Hi Community,
I have requirement to add breach time on task_sla table based on schedule- on SLA, Duration and start time.
I am triggering(creating )SLA from Flow designer but not calculating breach time.
How to Achieve This?
using below script but not helpful :-
var tz = gs.getSession().getTimeZone();
gs.info("tz<<<<<"+tz);
var currentDate = new GlideDateTime();
gs.info("currentDate<<<<<"+currentDate);
currentDate.setTZ(tz);
var days = 5;
var dur = new GlideDuration(60 * 60 * 24 * 1000 * 5);
gs.info("dur<<<<<"+dur);
var sch = current.schedule;
var schedule = new GlideSchedule(sch);
gs.info("schedule<<<<<"+schedule);
var DayCal = schedule.add(currentDate, dur, '');
gs.info("DayCal<<<<<"+DayCal);
current.u_pending_date_time = DayCal;
current.update();
Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2023 06:24 AM
HI @shweta14 ,
I trust you are doing great.
Create a new business rule that runs when a task SLA is created. This rule will execute the necessary script to calculate the breach time.
Navigate to "Business Rules" in ServiceNow and create a new record with the following details:
- Name: Calculate Task SLA Breach Time
- Table: task_sla
- When to run: Before
- Insert: true
- Update: true
In the script section of the business rule, write the following code:
(function executeRule(current, previous) {
var tz = gs.getSession().getTimeZone();
var currentDate = new GlideDateTime();
currentDate.setTZ(tz);
var days = 5;
var dur = new GlideDuration(60 * 60 * 24 * 1000 * days);
var sch = current.schedule;
var schedule = new GlideSchedule(sch);
var breachTime = schedule.add(currentDate, dur, '');
current.u_pending_date_time = breachTime;
})(current, previous);
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi