Flow Designer Action "Verify Inside Schedule"
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:
Outputs could be:
Using the inputs and outputs we've set up, the Script step could be something like:
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.
Result
Within a Flow Designer Flow or Subflow, you would now have the possibility to add the Action created.
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!
Kind regards,
Mar k Roethof
ServiceNow Technical Platform Architect @ Quint Technology
2x ServiceNow Developer MVP
2x ServiceNow Community MVP
---
https://www.servicenow.com/community/developer-articles/flow-designer-action-quot-verify-inside-schedule-quot/ta-p/2314708
