Unable to subtract duration using schedule Issue <!-- /*NS Branding Styles*/ --> .ns-kb-css-body-editor-container { p { font-size: 12pt; font-family: Lato; color: var(--now-color--text-primary, #000000); } span { font-size: 12pt; font-family: Lato; color: var(--now-color--text-primary, #000000); } h2 { font-size: 24pt; font-family: Lato; color: var(--now-color--text-primary, black); } h3 { font-size: 18pt; font-family: Lato; color: var(--now-color--text-primary, black); } h4 { font-size: 14pt; font-family: Lato; color: var(--now-color--text-primary, black); } a { font-size: 12pt; font-family: Lato; color: var(--now-color--link-primary, #00718F); } a:hover { font-size: 12pt; color: var(--now-color--link-primary, #024F69); } a:target { font-size: 12pt; color: var(--now-color--link-primary, #032D42); } a:visited { font-size: 12pt; color: var(--now-color--link-primary, #00718f); } ul { font-size: 12pt; font-family: Lato; } li { font-size: 12pt; font-family: Lato; } img { display: ; max-width: ; width: ; height: ; } } We have a scenario to subtract a number of business days from a date value. We are using script to get the schedules and calculating the duration.Addition works but the subtraction not working as expected. The script returning the same date instead of reducing the number of days mentioned. Release<!-- /*NS Branding Styles*/ --> .ns-kb-css-body-editor-container { p { font-size: 12pt; font-family: Lato; color: var(--now-color--text-primary, #000000); } span { font-size: 12pt; font-family: Lato; color: var(--now-color--text-primary, #000000); } h2 { font-size: 24pt; font-family: Lato; color: var(--now-color--text-primary, black); } h3 { font-size: 18pt; font-family: Lato; color: var(--now-color--text-primary, black); } h4 { font-size: 14pt; font-family: Lato; color: var(--now-color--text-primary, black); } a { font-size: 12pt; font-family: Lato; color: var(--now-color--link-primary, #00718F); } a:hover { font-size: 12pt; color: var(--now-color--link-primary, #024F69); } a:target { font-size: 12pt; color: var(--now-color--link-primary, #032D42); } a:visited { font-size: 12pt; color: var(--now-color--link-primary, #00718f); } ul { font-size: 12pt; font-family: Lato; } li { font-size: 12pt; font-family: Lato; } img { display: ; max-width: ; width: ; height: ; } } Any Release Cause<!-- /*NS Branding Styles*/ --> .ns-kb-css-body-editor-container { p { font-size: 12pt; font-family: Lato; color: var(--now-color--text-primary, #000000); } span { font-size: 12pt; font-family: Lato; color: var(--now-color--text-primary, #000000); } h2 { font-size: 24pt; font-family: Lato; color: var(--now-color--text-primary, black); } h3 { font-size: 18pt; font-family: Lato; color: var(--now-color--text-primary, black); } h4 { font-size: 14pt; font-family: Lato; color: var(--now-color--text-primary, black); } a { font-size: 12pt; font-family: Lato; color: var(--now-color--link-primary, #00718F); } a:hover { font-size: 12pt; color: var(--now-color--link-primary, #024F69); } a:target { font-size: 12pt; color: var(--now-color--link-primary, #032D42); } a:visited { font-size: 12pt; color: var(--now-color--link-primary, #00718f); } ul { font-size: 12pt; font-family: Lato; } li { font-size: 12pt; font-family: Lato; } img { display: ; max-width: ; width: ; height: ; } } When we are using GlideDuration with a negative duration is setting the date to 1969, but the ServiceNow calendar starts from Jan 1st 1970 which is the reason why the script is not working as expected. Resolution<!-- /*NS Branding Styles*/ --> .ns-kb-css-body-editor-container { p { font-size: 12pt; font-family: Lato; color: var(--now-color--text-primary, #000000); } span { font-size: 12pt; font-family: Lato; color: var(--now-color--text-primary, #000000); } h2 { font-size: 24pt; font-family: Lato; color: var(--now-color--text-primary, black); } h3 { font-size: 18pt; font-family: Lato; color: var(--now-color--text-primary, black); } h4 { font-size: 14pt; font-family: Lato; color: var(--now-color--text-primary, black); } a { font-size: 12pt; font-family: Lato; color: var(--now-color--link-primary, #00718F); } a:hover { font-size: 12pt; color: var(--now-color--link-primary, #024F69); } a:target { font-size: 12pt; color: var(--now-color--link-primary, #032D42); } a:visited { font-size: 12pt; color: var(--now-color--link-primary, #00718f); } ul { font-size: 12pt; font-family: Lato; } li { font-size: 12pt; font-family: Lato; } img { display: ; max-width: ; width: ; height: ; } } The recommended workaround is to use sched.add() with a positive duration, but move the reference date forward first, then work backwards logically - or more cleanly, use the GlideSchedule.duration() method approach below. Recommended Approach - Walk Backwards Using GlideSchedule.add() with a Positive Offset from a Shifted Anchor Since GlideSchedule does not natively support subtraction, the supported pattern is to add a positive duration to a past anchor date that you calculate by shifting the current date back by more than enough calendar days, then letting the schedule resolve forward. [code] var businessDaysToSubtract = 5; var hoursPerDay = 8; var currentDate = new GlideDateTime(); var schedRec = new GlideRecord('cmn_schedule'); schedRec.addQuery('name', 'Schedule Name'); schedRec.query(); if (schedRec.next()) { var sched = new GlideSchedule(schedRec.sys_id); // Step 1: Shift anchor back by 2x the business days as calendar days // (buffer ensures we don't go near epoch even for large values) var calendarBuffer = businessDaysToSubtract * 3; // conservative multiplier var anchorDate = new GlideDateTime(currentDate); anchorDate.addDays(-calendarBuffer); // native GlideDateTime method, no schedule needed // Step 2: Calculate the positive business duration to add from that anchor // We need to find how many business hours exist between anchorDate and currentDate, // then subtract the target business hours from that var totalBusinessHoursInBuffer = sched.duration(anchorDate, currentDate).getDurationValue(); // Step 3: Use add() from anchor with (buffer hours - target hours) as positive duration var bufferMillis = sched.duration(anchorDate, currentDate); var targetMillis = new GlideDuration(businessDaysToSubtract * hoursPerDay * 60 * 60 * 1000); // Net positive milliseconds to add from anchor var bufferMs = bufferMillis.getNumericValue(); var targetMs = targetMillis.getNumericValue(); var netMs = bufferMs - targetMs; if (netMs >= 0) { var netDuration = new GlideDuration(netMs); var result = sched.add(anchorDate, netDuration); gs.info("Business DateTime minus " + businessDaysToSubtract + " days: " + result.getValue()); } else { gs.info("Buffer too small - increase calendarBuffer multiplier"); } } [/code]