Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Why " isInSchedule() " always entering Else part

Supriya25
Tera Guru

Hi All,

I tried below , but it's always entering into ELSE Part.

It's returning UTC time value but I'm looking at EST timezone value validation.

var now= new GlideDateTime();

var nowDate = new GlideDateTime(now.getDisplayValueInternal());
var schedule = new GlideSchedule("090eecae0a0a0b260077e1dfa71da828"); 8-5 working days sys-id I took
if (schedule.isInSchedule(nowDate)) {
gs.info('It is in Schedule');
}else{

gs.info('It is Not in Schedule ');

}

always returning ' It is Not in Schedule  ' 

14 REPLIES 14

Astik Thombare
Tera Sage

Hi @Supriya25 ,

 

Please check below article it might be helpful -

 

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0787349

 

Thanks,

Astik

 

Not applicable

Hi @Supriya25 ,

 

I checked your problem in my PDI, but unfortunately I didn't find that sys_id that you mentioned "090eecae0a0a0b260077e1dfa71da828", may be could you please tell me from where you got that sysId.

 

Thanks and Regards 

Sarthak

Bert_c1
Kilo Patron

Hi @Supriya25 

 

The following code works for me:

 

 

var now= new GlideDateTime();

//var nowDate = new GlideDateTime(now.getDisplayValueInternal());
var nowDate = new GlideDateTime(now.getDisplayValue());
gs.info ("Checking date = " + nowDate);
var schedule = new GlideSchedule("090eecae0a0a0b260077e1dfa71da828"); // 8-5 weekdays excluding holidays
if (schedule.isInSchedule(nowDate)) {
gs.info('It is in Schedule');
}else{
gs.info('It is Not in Schedule ');
}

// now check using a value that is in the schedule, since the above is getting current date-time. and can't be tested until Monday.
nowDate = new GlideDateTime();
nowDate.setDisplayValue("2024-04-15 10:06:00");
gs.info ("Checking date = " + nowDate);
var schedule = new GlideSchedule("090eecae0a0a0b260077e1dfa71da828"); // 8-5 weekdays excluding holidays
if (schedule.isInSchedule(nowDate)) {
gs.info('It is in Schedule');
}else{
gs.info('It is Not in Schedule ');
}

 

 

DateTime value is in Local time, not UTC. Output is:

 

*** Script: Checking date = 2024-04-13 09:11:54
*** Script: It is Not in Schedule 
*** Script: Checking date = 2024-04-15 14:06:00
*** Script: It is in Schedule

You have given 2024-04-15 10:06:00, then it should return the Same Date/Time right ? then how come it s returning 14:06:00

10:06:00 means morning time right so it should be in Scheduled. but it is giving  14:06:00.