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 01:34 PM
Could you please explain how I can get this into a form that I could view for errors? I am not aware of how to do that with a catalog item.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-17-2016 02:12 PM
You can run background script using the current record someting like below:
var gr = new GlideRecord("Table Name");
gr.get('SYSID of Record you are testing on');
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 03:32 PM
Now this is getting bizarre... When I run that script, it says that endDate is undefined: "End date is: undefined Current Date is: 2016-06-17"
My variable name is for sure "offboard_effectivedate", http://puu.sh/pwvAl/3c39960719.png
If I look up the variable relationships for this sys_id, the date is coming across: http://puu.sh/pwvG2/57d7a48864.png
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-17-2016 03:42 PM
Shane,
I am assuming you have replaced Table name and Sys Id with Table you are working on and Sys ID of the record respectively. If Yes endDate should populate correctly. I was unable to open images you sent.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-17-2016 03:47 PM
Yes I changed the table to be sc_req_item, and the sys_id to be the sys_id of my requested item.