How to pause the workflow till next schedule start time?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2023 04:28 AM
Hello Team,
I have a requirement related to implementing an 'On Call Support' feature for the incident process. To clarify, my working hours are from 9:30 AM to 6:00 PM. If an incident is created after working hours (from 6:00 PM to 9:29 AM), I want a specific workflow (On Call Functionality) to execute.
Here's how I've implemented the logic: If a request is created after 6:00 PM, it waits for 15 minutes using a configured timer. During this time, the incident remains assigned to the default group (Group-1). After 6:45 PM, if no action occurs, the incident is then assigned to a predefined on-call support group (Group-2).
Within Group-2, if there are two users, the first user receives a call for 5 minutes (as per our defined time). If user-1 doesn't respond, the incident is escalated to user-2. If neither user responds, I want the workflow to pause until the next working day begins at 9:30 AM. At that time, the incident should be reassigned back to Group-1.
My concern is how to pause the workflow timer from the moment Group-2 users don't respond until the next day's working hours (9:30 AM) and then reassign it to Group-1.
Thanks,
Raj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2023 08:41 AM
Hi @Raj90 ,
To achieve the workflow pause until the next working day, you can follow these steps in your ServiceNow workflow:
-
Identify Working Hours:
- Determine your working hours. In your case, it's from 9:30 AM to 6:00 PM.
-
Calculate Time Remaining Until Next Working Day:
- When neither user in Group-2 responds, calculate the time remaining until the next working day (9:30 AM of the next day).
-
Use "Wait for" Timer Event:
- Use a "Wait for" Timer Event in the workflow.
- Calculate the time remaining from the current time until the next working day.
- Set the timer to wait until the calculated time.
-
Assign Back to Group-1:
- After the "Wait for" Timer Event, add an activity to assign the incident back to Group-1.
Here's an example of what the workflow logic might look like:
(function executeRule(current, previous /*null when async*/) {
// Assuming 'responseReceived' is a flag indicating if users in Group-2 responded
var responseReceived = current.responseReceived;
if (!responseReceived) {
// Calculate time remaining until 9:30 AM of the next working day
var now = gs.nowDateTime();
var nextWorkingDay = new GlideDateTime();
nextWorkingDay.setDisplayValue('09:30:00');
nextWorkingDay.addDays(1); // Next working day
// Calculate the duration until the next working day
var duration = new GlideDuration(nextWorkingDay.getNumericValue() - now.getNumericValue());
var durationSeconds = duration.getNumericValue() / 1000;
// Wait for the calculated duration
gs.sleep(durationSeconds);
// Assign the incident back to Group-1
current.assignment_group = 'Group-1';
current.update();
}
})(current, previous);
Thanks,
Ratnakar