- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2015 05:51 AM
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2015 03:00 PM
You can use a "Timer" activity with the "Timer based on" field set to "Script":
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2015 01:42 PM
You can do it in the opposite direction, but its dangerous since Last_Name is not unique.
What I was thinking is on a User insert you scan through your open task records looking for the shared unique value (in whatever field you're storing it), then you pump an update to work notes and make your Wait For Condition look for that.
Its clunkier than I like, but it might work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2015 02:23 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2015 01:33 PM
Wait For Conditions only evaluate on updates to the record the workflow is in context of. So I don't think that script will work as it would require a check every second until the appropriate time.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2015 03:00 PM
You can use a "Timer" activity with the "Timer based on" field set to "Script":
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2015 04:28 PM