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

Hi Shane,



Making changes in PROD on my recommendations... scary.       But I was going to say, you could also setup a temporary schedule just for testing, and point your script at that instead... just to see how it works.



For your temp schedule:


  1. Set it up with a block of working hours including the current time.
  2. Test.
  3. Change the block of hours so that (now) is excluded.
  4. Test.


That should get you an answer much quicker.   It doesn't have to be like Christmas eve, although... what fun.




Also as a suggestion, I like to use Fix Scripts to test out functionality like this.


  1. Just take your script being used and paste it into a new Fix Script.
  2. Hard code some values for your incoming variables.
    (or you can include a GlideRecord query to actually pull a valid record to work with... just don't forget to change "current" to your GlideRecord variable i.e., "gr" for testing, and to change back to "current" if you paste back to your original script.   Learn from my mistakes)
  3. Add in some gs.print(...) statements to check the results, and away you go.





-Brian


I meant that this schedule is the same one we use in Production, and is working. This new script and workflow is in our Test environment


Hi Shane,



Any luck?



If not, the first thing I'd look at is the format of your stored date (current.variables.offboard_effectivedate).   Using "gs.now()" gets the date in the current user's defined format... if the formats don't match, neither will your condition, because you're comparing strings.



In that case, you could either try to enforce formatting on the values or convert the values to actual date objects for comparison.




Thanks,


-Brian


Just looking at it now, and it would seem that the Wait If is still running - the condition to wait for a gs.now time that matches my variable date/time, within the schedule, has not yet returned a 'true'.



I logged a test item yesterday, with a date of today (the 17th), and the date coming across from my variable is: 2016-06-17.


Running a background script of: "gs.log(gs.now());" returns a value of 2016-06-17.



Thoughts?




To recap, the script I used was the following:



var endDate = current.variables.offboard_effectivedate;


var currentDate = gs.now();


if (endDate == currentDate){


  var sched = new GlideSchedule('935aaa204a36232b00a80c0ba29522cf');


  if (sched.isInSchedule(currentDate)){


  answer = true;


  }


  else


  {


  answer = false;


  }


}


else


  {


  answer = false;


}


It all looks ok on the surface... I would


  1. move it to a Fix Script for testing,
  2. use a GlideRecord to pull the same current record you are using for testing,
  3. and use gs.print(...) to check all the values you're getting in the script, including the schedule comparison.



Look for any inconsistencies, see if there is an error being thrown, etc.   It's not that complex a script




-Brian