Flow Designer Action "Verify Inside Schedule" - ServiceNow Community
Mark Roethof
Tera Patron
Tera Patron

Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

 

Hi there,

 

Sometimes you just need to verify if a certain Date/Time is within a Schedule or not. Browsing the ServiceNow Community you will come across several (good) solutions. Ideally you would have such a solution available in such a way, that you can re-use it easily. For example using a Script Include, or… Flow Designer action!


GlideSchedule API

Key of verifying if a Date/Time is within a Schedule is the "GlideSchedule" API. There are several functions for this API, though we are specifically interested in "isInSchedule". Looking at the Docs, usage could be something like: 

 

var sched = new GlideSchedule(schedule_sys_id);
var date = new GlideDateTime();

if(sched.isInSchedule(date))
    gs.info("Is in the schedule");
else
    gs.info("Is NOT in the schedule");


Action

We just need to transform the script mentioned, into a Flow Designer Action. Just adding that the Schedule and Date/Time could be provided as inputs to make the Action dynamic and that the Action returns an output which represents if the Date/Time provided is within the provided Schedule.

 

Inputs could be:

 

find_real_file.png

 

Outputs could be:

 

find_real_file.png

Using the inputs and outputs we've set up, the Script step could be something like:

 

find_real_file.png

Now simply save and publish the Action!


Schedule

Sure, obviously you do need to have a Schedule available. If this concerns a Date/Time check for within working hours of a workday Schedule, just have a look if your company already has such a Schedule.

 

Though what If you would like to check if the Date/Time is on a workday, not specifically within the working hours? You could solve this with some complex scripting, or… just creating a new Schedule. A new Schedule, which would have the same days and child (holiday) Schedule as your regular workday Schedule. The only difference that this new Schedule does not run from 9 AM till 5 PM, though 24 hours.

 

find_real_file.png


Result

Within a Flow Designer Flow or Subflow, you would now have the possibility to add the Action created.

 

find_real_file.png

 

Output of the Action would be a true/false boolean.

 

For example you could now verify if a Date/Time field from a queried record, is within a Schedule. Because the Date/Time field is not mandatory (and by default the current Date/Time) you could also use this Action to verify if when the Flow is running, is within a Schedule.


Share

An Update Set with this Flow Designer Action can be downloaded from Share:
- Flow Designer Action "Verify Inside Schedule"

---


And that's it actually. If any questions or remarks, let me know!

 

C

If this content helped you, I would appreciate it if you hit bookmark or mark it as helpful.

 

Interested in more Articles, Blogs, Videos, Podcasts, Share projects I shared/participated in?
- Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

 

Kind regards,


Mark Roethof

ServiceNow Technical Platform Architect @ Quint Technology

2x ServiceNow Developer MVP

2x ServiceNow Community MVP

---

LinkedIn

Comments
OlaN
Giga Sage

Very useful, love it!

Edward Scholes
Tera Contributor

Thanks Mark - just what we needed. Quick note to anyone else who stumbles on this thread - still working as of Sept 2023.

gana2
Tera Contributor
nonamenic
Tera Contributor

Thank you for this Mark. Extremely helpful, no longer need to work with 'wait for duration of time' to get this functionality working. 

VarunS
Tera Guru

@Mark Roethof The schedule_sys_id is the sys id of the schedule or scheduled entry?

VarunS
Tera Guru

@Mark Roethof This flow action doesnt work for me. I have utilised your update set and tested it in flow designer. 

Below is my schedule. 

VarunS_0-1715880923116.png

When I test it with the sys id of the schedule (not the scheduled entry) I get the below results which is incorrect. Could you suggest what am doing wrong?

 

VarunS_1-1715881255933.pngVarunS_2-1715881273745.png

 

Priyanka Chaud1
Tera Contributor

@VarunS same for me the action is not working any solution u got?

paulc1974
Tera Expert

The action does work for me.  What I did notice is that schedule entries need to have nothing set in the "Type" field for it to work.  When previously populated with a value, it doesn't work.

 

Admittedly, not sure this is the same as the issue you have but just sharing in case.

 

Paul

 

paulc1974_0-1720105275051.png

 

Version history
Last update:
‎08-12-2024 09:07 AM
Updated by:
Contributors