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-17-2016 03:54 PM
Check if variable is misspelled. If not it should populate correctly in Background script. As it is showing it has undefined, the condition is failing and the workflow is stuck.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-17-2016 04:50 PM
HI Shane,
Can you paste in the script that you're now using to test?
Thanks,
-Brian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-17-2016 05:12 PM
I am off the weekend, but will be back on this Monday morning. Thank you everyone for your continued assistance.
Here is the script that I'm running:
var gr = new GlideRecord("sc_cat_item");
gr.get('21cbbd424f486240f1b6926ca310c7ef');
var endDate = gr.variables.offboard_effectivedate;
var currentDate = gs.now();
gs.print("End date is: "+endDate+" Current Date is: "+currentDate);
if (endDate == currentDate){
gs.print("Condition is Met");
var sched = new GlideSchedule('935aaa204a36232b00a80c0ba29522cf');
if (sched.isInSchedule(currentDate)){
gs.print("Getting Inside the schedule");
answer = true;
}
else
{
answer = false;
}
}
else
{
answer = false;
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-17-2016 05:50 PM
Shane,
You need to change the GlideRecord (1st line) to point to the Requested Items [sc_req_item] table instead. The Catalog Items [sc_cat_item] table stores the items defined for your catalog. The Requested Items table is where the actual task gets generated when someone orders something and supplies values for the variables.
var gr = new GlideRecord("sc_req_item");
gr.get('21cbbd424f486240f1b6926ca310c7ef');
var endDate = gr.variables.offboard_effectivedate;
var currentDate = gs.now();
gs.print("End date is: "+endDate+" Current Date is: "+currentDate);
if (endDate == currentDate){
gs.print("Condition is Met");
var sched = new GlideSchedule('935aaa204a36232b00a80c0ba29522cf');
if (sched.isInSchedule(currentDate)){
gs.print("Getting Inside the schedule");
answer = true;
}
else{
answer = false;
}
}
else{
answer = false;
}
Thanks,
-Brian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-20-2016 09:49 AM