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

pavank
Kilo Contributor

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.


HI Shane,



Can you paste in the script that you're now using to test?




Thanks,


-Brian


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;


}


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


Ah right you are!



Running that, I get back both dates.



Logging a new catalog item for this to check my workflow again, at the "Wait for" condition, I am getting the following new error (was not doing this previously):



offboard workflow Wait For error.png


Line 6 is the following:


if (sched.isInSchedule(currentDate)){