How to include a schedule in a workflow "Wait if condition" script

SC10
Kilo Guru

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;

}

26 REPLIES 26

Remember, you have to use a date/time object to check the schedule, but using gs.now() just returns a date.



That's why we used this instead:



var currentDateTime = new GlideDateTime();


if (sched.isInSchedule(currentDateTime)){...}




-Brian


The activity is working with the variable now being GlideDateTime. Thanks for the reminder on using that.



I will run this catalog item outside of my schedule this afternoon for another test, but in the mean time do you know why the background script is always returning undefined for:


var gr = new GlideRecord("sc_req_item");


gr.get('3Dfed3b33e4f08e240583800fe9310c7c6');


var endDate = gr.variables.offboard_effectivedate;



Is there perhaps another way to pull out the variables from an sc_req_item that's being missed? If call a variable for gr.sys_id, and print it, it does return the sys_id. If I call a variable for gr.short_description, or gr.number, it comes back Undefined.


Furthermore, I am running the background script in attempts to get the endDate variable, and it is still not returning and just comes up as 'undefined':



var gr = new GlideRecord("sc_req_item");


gr.get('3Dfed3b33e4f08e240583800fe9310c7c6');


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;


}


One of the reason I suspect you are still not returning back from wait for condition is that your record on which workflow is configured expecting an update.


If you update it, then your wait for condition will evaluate again, your update will act as a trigger to force wait for condition.


Interesting point. Is there a way to force an update of the record within the workflow, on some sort of scheduled timer?