- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2016 11:15 AM
I'm new to SN scripting and looking for a bit of help here. I've setup an inactivity workflow to send alerts when there has not been any updates to an incident based on the priority. I'm fine with the workflow portion, but need some help in the business rules to start, cancel and restart the workflow.
Using another article on here, I am borrowing the scripts from this link to cancel and restart the WF based on certain events/field updates:
Restart workflow when incident assignment group changes
However, I can't seem to get the business rule setup to start the workflow when an incident is created.
The business rule I have created is set to run on Insert (tried both before and after), but it doesn't want to fire off the workflow.
Here is what I have on the script: (Note, I re-used the code from the link, so there is probably a bit more than what is needed in here)
Any help is appreciated, thanks
(function executeRule(current, previous /*null when async*/) {
//where current is a task record with a workflow context
var wf = new Workflow().getContexts(current);
while(wf.next()) {
if (wf.hasWorkflow('4ad0eba0db436200675ef0c6ae96191a'));
wf.deleteWorkflow(current);
new Workflow().startWorkflow('4ad0eba0db436200675ef0c6ae96191a');
current.work_notes = "The HL - IT Inactivity workflow has been started.";
}
})(current, previous);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2017 12:03 PM
Sorry, late in responding or posting this as closed. Here is the final script that works to restart the specific inactivity workflow that is in play. FYI, inactivity monitors didn't work for our situation:
(function executeRule(current, previous /*null when async*/) {
//where current is a task record with a workflow context
var wf = new Workflow().getContexts(current);
while(wf.next()) {
if (wf.hasWorkflow('196797acdb036200675ef0c6ae96193c'));
wf.deleteWorkflow(current);
new Workflow().restartWorkflow(current);
}
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2016 12:13 PM
Is it too late to point you to something out of the box - Inactivity Monitors http://wiki.servicenow.com/index.php?title=Setting_Inactivity_Monitors#gsc.tab=0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2017 12:03 PM
Sorry, late in responding or posting this as closed. Here is the final script that works to restart the specific inactivity workflow that is in play. FYI, inactivity monitors didn't work for our situation:
(function executeRule(current, previous /*null when async*/) {
//where current is a task record with a workflow context
var wf = new Workflow().getContexts(current);
while(wf.next()) {
if (wf.hasWorkflow('196797acdb036200675ef0c6ae96193c'));
wf.deleteWorkflow(current);
new Workflow().restartWorkflow(current);
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2022 11:41 PM
Hi
Here in this line of the code
if (wf.hasWorkflow('196797acdb036200675ef0c6ae96193c'));
what is the sys ID you mentioned here?