How to include a schedule in a workflow "Wait if condition" script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2016 09:39 AM
I'd like to include one of my custom schedules into a "Wait if condition" script. The wiki is very vague on how to include in checks to a custom schedule, so I thought I'd share my simple script and see if anyone had opinions on the best way to include a schedule check.
My end-goal is to have my "Wait if condition" result in true when the current date equals my variable's day, but also within the constraints of my schedule (so instead of at the stroke of midnight on the "same" day, the Wait If only continues to the next workflow activity within my scheduled hours:
var endDate = current.variables.offboard_effectivedate;
var currentDate = gs.now();
if (endDate == currentDate){
answer = true;
}
else
{
answer = false;
}
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2016 10:17 AM
Hi Shane,
Here's one way you can check a date/time against your schedule:
var endDate = current.variables.offboard_effectivedate;
var currentDate = gs.now();
if (endDate == currentDate){
var sched = new GlideSchedule(sys_id of your Schedule's record);
if (sched.isInSchedule(currentDate)){
answer = true;
}
else{
answer = false;
}
}
else{
answer = false;
}
See how that works for you.
Thanks,
-Brian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2016 10:30 AM
Thanks for the quick reply.
To clarify, this addition will have answer equalling to true only when the current date is my variable's date, and also if the current day is in my schedule? This makes me wonder how my schedule will play into this as my schedule is simply a block of hours in a normal workday, and no weekends. I'd ideally only want the True condition to happen when my work day hours begin. Do I have to do something akin to "current hour" or will keeping to "currentDate" be fine? I ask because my currentDate variable is only a glidedate, and not a glidedatetime.
Thank you.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2016 10:45 AM
Hi Shane,
That's how the above script should work... it will ONLY perform the check against your schedule when (endDate == currentDate). To be clear, your schedule needs to be defined under System Scheduler>Schedules (or by going to the Schedules [cmn_schedule] table). If you haven't already, create your schedule here and add all the schedule entries you need to define your workday hours.
As for the script and using date/time, you're right. You'll need to adjust it just a little:
var endDate = current.variables.offboard_effectivedate;
var currentDate = gs.now();
if (endDate == currentDate){
var sched = new GlideSchedule(sys_id of your Schedule's record);
var currentDateTime = new GlideDateTime();
if (sched.isInSchedule(currentDateTime)){
answer = true;
}
else{
answer = false;
}
}
else{
answer = false;
}
This should return true only if both of your conditions are met.
-Brian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2016 10:54 AM
My schedule is in use within our production environment already and will be called here in the script.
I've made your recommended changes and will know tomorrow at the start of the business day hours if the Wait If condition will be comes True or not. Thank you for your help so far, I should be able to provide an update tomorrow morning.