Trigger event/something at specific date and time

Rshear
Kilo Expert

Hi All,

I'm looking for possible solutions to the below:

I need to change the status of a business service (CI class) at a time and date specified on another record. E.g. when a change is raised against a business service I want the business service state to change when the change implementation date and time hits (as seen on the change record).

Obviously this is a one off (i.e. different for every change) and the dates and times can be different so based on my experience scheduled jobs doesnt feel like the way to go. I could also trigger a scheduled event but believe they only stay in the queue for 7 days.

Has anyone got any tip, advice or experience on how to do this?

6 REPLIES 6

Hi Russell,



Here is a script timer based on an input variable that we use that you can use as a sample:



//setup glideDateTime's for the termdate at 2am UTC, which is 6pm PST, that way when we getDisplayValue our dates are accurate


// after whatever timezone change it's going to get based on the user that initated this workflow.


var termDateVar = current.variables.hrterm_term_date.toString();


var termDate = new GlideDateTime(termDateVar + ' 02:00:00');


termDate.addDaysLocalTime(1);


var now = new GlideDateTime(gs.nowNoTZ());


//get the difference and return seconds.


var timerDuration = gs.dateDiff(now.getDisplayValue(), termDate.getDisplayValue(), true);


gs.log(current.number + ' - timer info - termDateVar: ' + termDateVar + ' termDate: ' + termDate.getDisplayValue() + ' Now: ' + now.getDisplayValue() + ' Diff: ' + timerDuration);


//setting answer to number of seconds


answer = timerDuration;



And here is the Run Script in the workflow that I screenshotted above used in a loop with a static timer:



var startDateVar = current.u_emp__action_effective_date;


var startDate = new GlideDateTime(startDateVar + ' 07:00:00');


startDate.addDaysUTC(-3);


var now = new GlideDateTime(gs.nowNoTZ());



if (now >= startDate) {


  workflow.scratchpad.firstEmailSent = now;


  workflow.scratchpad.threeDays = "true";


} else {


  workflow.scratchpad.threeDays = "false";


}



Both are keying off of a catalog item variable as an input to determine when to progress.


Robert's input is beautiful and exactly where I was headed with this topic.



To answer your question about "how can I tell how long to wait?"... this timer solution that I suggested and Robert provided example scripting for sets a different timer dynamically for each workflow context. So, for example, someone creates a Change Request with:



  • Planned start of November 30, 2015 @ 14:00:00
  • Triggers workflow which causes the Timer Activity to start on November 17 @ 10:00:00


If you review the Workflow Context, you will find that the Timer Activity automatically calculates the duration between these two dates and sets a timer for 13 days, 4 hours, 0 minutes and 0 seconds.



Between Robert and my posts, are we answering your questions so far?