GlideSchedule subtract script giving 'undefined' output

claires74644296
Tera Contributor

Hi all,

 

Please could someone advise why the below is giving me undefined as an answer? Does the glideschedule subtract method no longer exist? If so can anyone help me with an alternative approach?

 

var startDate = new GlideDateTime('2024-01-02');
var days = 5;
var dur = new GlideDuration(60 * 60 * 24 * 1000 * days);
var schedule = new GlideSchedule('43b7baabdb4407002328384c7c96aaaaa');
var end = schedule.subtract(startDate, dur);
gs.info(end);
 
What I need is to calculate 5 working days prior to a 'start_date' variable on a specific ritm. 
 
Many thanks!
1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@claires74644296 

you want to subtract 5 business days and get the date/time?

If yes then check these links, the logic you are using won't work as that's not how you calculate business days

Also remember to use correct schedule sysId

subtract time from schedule to update task due date 

Calculate Date By Adding or Subtracting Time With A Schedule 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

4 REPLIES 4

Maik Skoddow
Tera Patron
Tera Patron

Hi @claires74644296 

the given Sys ID 43b7baabdb4407002328384c7c96aaaaa is wrong as it has 33 characters. A valid Sys ID in ServiceNow must have 32 characters. Maybe a copy and paste issue?

Maik

Ah no I changed that on purpose for this post, the sys id I've been using in the system is definitely correct. 

Ankur Bawiskar
Tera Patron
Tera Patron

@claires74644296 

you want to subtract 5 business days and get the date/time?

If yes then check these links, the logic you are using won't work as that's not how you calculate business days

Also remember to use correct schedule sysId

subtract time from schedule to update task due date 

Calculate Date By Adding or Subtracting Time With A Schedule 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

claires74644296
Tera Contributor

Thanks so much Ankur, the second link worked like a charm!

I'd seen more recent community posts using a schedule.subtract method hence why I was using what I did, but none of them had worked for me