The CreatorCon Call for Content is officially open! Get started here.

How to wait until specific time of day?

josh_tessaro
Giga Expert

We have a scenario where we need a workflow to pause until at or after the next occurrence of 4:00 AM. When a network account request is completed, we want to wait until after the new user record is inserted into service-now (4:00 AM) before kicking off the other items on the request.

Any suggestions on how to set up an activity that will always wait until the next occurrence of <time>?

EDIT: The end goal here was to wait until a new sys_user was inserted from AD, which I have done using my below solution. It turns out using a wait for or timer is not the best way to accomplish this but a timer solution that works has been marked as the correct answer.

I am checking if there is more than one sys_user matching last name and created in the last day. If yes I continue, if no I wait an hour and repeat.

SS052.bmp

1 ACCEPTED SOLUTION

Jim Coyne
Kilo Patron

You can use a "Timer" activity with the "Timer based on" field set to "Script":


ServiceNow.png



And this would be your script:



// Set 'answer' to the number of seconds this timer should wait


answer = (function(){


  var gdtToday = new GlideDateTime();


  var gdtTomorrow = new GlideDateTime();


  gdtTomorrow.addDaysLocalTime(1);


  gdtTomorrow.setDisplayValue(gdtTomorrow.getLocalDate() + " 04:00:00");   //careful, there's a leading space before 04:00:00


  //calculate wait time


  var wait = gs.dateDiff(gdtToday.getDisplayValue(), gdtTomorrow.getDisplayValue(), true);


  return wait;


})();



The script calculates the number of seconds before 4:00 am the next day.


View solution in original post

10 REPLIES 10

Could you please suggest me.

 

Request should not proceed until after 5:00pm if request is entered between 7am-5pm.

 

Please let me know the possibilities.