I am trying to fetch the date from present date to past date of 3 business days,i am using below script but it fetches the future date..Can any one suggest me which script i need to use for past days of business days?

Chaitanya6
Tera Contributor

var startDate = new GlideDateTime();
var days = 3;
var dur = new GlideDuration(60 * 60 * 24 * 1000 * days);
var schedule = new GlideSchedule('090eecae0a0a0b260077e1dfa71da828');
var end = schedule.add(startDate, dur);

gs.print(startDate);
gs.print(end);

5 REPLIES 5

SanjivMeher
Kilo Patron
Kilo Patron

Check below thread, if it helps

https://community.servicenow.com/community?id=community_question&sys_id=032e436fdb7793408e7c2926ca96...


Please mark this response as correct or helpful if it assisted you with your question.

Chaitanya6
Tera Contributor

Thank you, Sanjiv for sharing the thread.

I looked into your post and I created a script include class as he provided in the post but is I'm not able to fetch the past date of business days, It's fetching the normal days only.

Any suggestions from your side

 

Thanks in advance 

Chaitanya.

So you new script should be

 

var startDate = new GlideDateTime();

var su = new ScheduleUtils();

varend = su.subDaysInSchedule("<Name of the schedule>",startDate, 3);

gs.info(startDate);
gs.info(end);

 

Can you post your script it is different from above?


Please mark this response as correct or helpful if it assisted you with your question.

Abhijit4
Mega Sage

Hi Chaitanya,

Please try below script,

var startDate = new GlideDateTime();
var days = -3;//we need to use here -3 as you need past records
var dur = new GlideDuration(60 * 60 * 24 * 1000 * days);
var schedule = new GlideSchedule('090eecae0a0a0b260077e1dfa71da828');
var end = schedule.add(startDate, dur);

gs.print(startDate);
gs.print(end);

 

Let me know if you have any further queries.

Please mark this as Correct or Helpful if it helps.

Thanks and Regards,
Abhijit
Community Rising Star 2022

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP