We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

Find if Schedule entry is currently active

karanpreet
Tera Guru

Hello All,

 

I'm trying to write a maintenance rule for event management that would add all the servers with a maintenance schedule attached into maintenance from an Alerting prospective.

 

I have most of the rule in place but I see an issue. 

 

The Date/Time field I get for the schedule start and end time is in the cmn_schedule_span table is of time Schedule Date/Time.

 

This format seems to be a string like yyyyMMDDTHHmmSSZ e.g.  "20240211T070000Z". 

 

I tried creating a new DateTime object using the below code out of this but that doesn't work.

 

var start_date = new GlideDateTime(schedule_span.start_date_time);

 

I need to compare this with the current time so I would need a datetime object for both of them. I can use string parsing to separate the above format out but ideally this format should be supported especially when it's in the schedule table.

 

Is there perhaps a better way to find if a schedule is currently active?

 

Any help would be great.

 

Thanks,

Karan

1 REPLY 1

Kieran Anson
Kilo Patron

Hi Karan,

What is the purpose of checking if the current date time matches the start of a schedule? Are you wanting to check if the current time is within a scheduled period? If so, use the provided GlideSchedule API to do so GlideSchedule | ServiceNow Developers