Cancelling Change Workflow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-29-2016 11:40 AM
Hi everyone, am working on business rule to cancel change request workflow when a change is made to the Change Type (Out of Process follows one workflow; Standard follows another).
I found an article 'Cancelling Change Workflow' that was posted in May, 2014 (Cancelling Change Workflow) and incorporated what was said in that article into the Business Rule I'm working on. It works except for the following issues -
- The comment isn't being added to Approval History - I've added Approval History to my Activities and nothing shows up. Don't have much scripting experience but one of my internal developers gave the business rule a look and said it should be working
- When the change type switches from Out of Process to Standard, the workflow is cancelled and the new workflow is attached. If the Change Type is then switched from Standard to Out of Process, the workflow cancels, but the new workflow isn't attached. Just curious why this is happening, though am not too upset about this one because I can see an never-ending circle.
Appreciate any help with clearing this up!! We're on Fuji.
Used the OOB business rule 'SNC Approval - Reset conditions and modified per the script instructions and added script from 'Cancel Workflows Upon Cancellation'.
Full script -
// these are the conditions under which the change request approvals need to be cancelled and reset
// steps to activate
// 1. enable this business rule
// 2. add some comments so the reset will be noted in the approval history
// 3. uncomment the code for restart or reset based on your requirements
// 4. define the reset condition in checkResetConditions function below
// 5. you must set doReset once you capture the change(s) you are interested in
var comment = 'Change Type has been changed - marking all existing approvals No Longer Required and creating new approvals'; //written to the approval_history
if (checkResetConditions()) {
// create a global variable lock on the current record
// this will prevent triggering a second reset while the first reset is still in progress
// lock will be release in a late running business rule called 'Workflow Release Lock'
chg_wf_lock = new GlideRecordLock(current);
chg_wf_lock.setSpinWait(50); //wait for lock
if (chg_wf_lock.get()) {
gs.print('SNC Approval conditions business rule is locking the ' + current.getDisplayValue() + ' during the workflow reset');
// The following options are available for resetting the approvals:
//
// 1. Mark all existing approvals for the change as 'cancelled' and restart the workflow to create new approvals - activating 6/23/16 by LHoffman
new WorkflowApprovalUtils().cancelAll(current, comment);
new Workflow().restartWorkflow(current);
//
// 2. Delete all of the existing approvals for the change and restart the workflow to create new approvals
// new WorkflowApprovalUtils().reset(current, comment);
// gs.addInfoMessage('Workflow has been reset since key fields have been modified');
//
// 3. Leave the approvals for the change in their current state and restart the workflow.
// (so that any new approvals that are required will be created)
// if (comment)
// current.setDisplayValue('approval_history', comment);
// new Workflow().restartWorkflow(current, true);
//
}
}
function checkResetConditions() {
var doReset = false; //default to no reset
//add reset conditions here such as:
//if (current.type.changes())
// doReset = true; //enable the reset
//
return doReset;
}
// Cancel existing workflow - added by LHoffman 06-23-16 from Cancel Workflows Upon
// Cancellation business rule per community article suggestion titled 'Cancelling
// Change Workflow'
cancelMyWorkflows();
function cancelMyWorkflows() {
//get workflow helper
var workflow = new Workflow();
//cancel all my workflows
var numCnxd = workflow.cancel(current);
if (numCnxd > 1)
gs.addInfoMessage(numCnxd + " " + gs.getMessage("Workflows for {0} have been cancelled", current.getDisplayValue()));
else if (numCnxd == 1)
gs.addInfoMessage("1 " + gs.getMessage("Workflow for {0} has been cancelled", current.getDisplayValue()));
}
- Labels:
-
Service Mapping

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2016 07:33 AM
Under: // The following options are available for resetting the approvals:
You uncommented #1, which is all you needed to do, but I see you added a cancelMyWorkflows() which you shouldn't need as #1 is going to restart the workflow not cancel it.
Not that I see the full script, the comment is going to show under the Approvers list as some approvers will have to approved again, and the comment will explain why.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2016 08:35 AM
I had to have it cancel the workflow because the reset was cancelling the approvals but not the workflow so we had multiple workflows attaching. But it's not putting the comment anywhere. Here's an example - just submitted this as 'Standard'.
Changed 'Change Type' to 'Out of Process'. Get the message '1 Workflow for CHG0031105 has been cancelled', and the approvals all go to 'No longer required' however no comment is placed on any of them, which is what i thought the script was going to do. I don't have any scripting experience and am piecing this together as best i can.
When I click 'Request Approval', the Out of Process workflow attaches and adds the approvers again, which is what i'm expecting. Just not getting the comment and not sure what to do next.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2016 09:51 AM
Let me try and test this in my instance at little later and get back to you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2016 10:06 AM
Awesome, thank you!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2016 11:10 AM
This script works fine when the type changes. 2 changes I made are in Bold:
// these are the conditions under which the change request approvals need to be cancelled and reset
// steps to activate
// 1. enable this business rule
// 2. add some comments so the reset will be noted in the approval history
// 3. uncomment the code for restart or reset based on your requirements
// 4. define the reset condition in checkResetConditions function below
// 5. you must set doReset once you capture the change(s) you are interested in
var comment = 'This is a test'; //written to the approval_history
if (checkResetConditions()) {
// create a global variable lock on the current record
// this will prevent triggering a second reset while the first reset is still in progress
// lock will be release in a late running business rule called 'Workflow Release Lock'
chg_wf_lock = new GlideRecordLock(current);
chg_wf_lock.setSpinWait(50); //wait for lock
if (chg_wf_lock.get()) {
gs.print('SNC Approval conditions business rule is locking the ' + current.getDisplayValue() + ' during the workflow reset');
// The following options are available for resetting the approvals:
//
// 1. Mark all existing approvals for the change as 'cancelled' and restart the workflow to create new approvals
new WorkflowApprovalUtils().cancelAll(current, comment);
new Workflow().restartWorkflow(current);
cancelMyWorkflows();
//
// 2. Delete all of the existing approvals for the change and restart the workflow to create new approvals
// new WorkflowApprovalUtils().reset(current, comment);
// gs.addInfoMessage('Workflow has been reset since key fields have been modified');
//
// 3. Leave the approvals for the change in their current state and restart the workflow.
// (so that any new approvals that are required will be created)
// if (comment)
// current.setDisplayValue('approval_history', comment);
// new Workflow().restartWorkflow(current, true);
//
}
}
function checkResetConditions() {
var doReset = false; //default to no reset
//add reset conditions here such as:
if (current.type.changes())
doReset = true; //enable the reset
//
return doReset;
}
function cancelMyWorkflows() {
//get workflow helper
var workflow = new Workflow();
//cancel all my workflows
var numCnxd = workflow.cancel(current);
if (numCnxd > 1)
gs.addInfoMessage(numCnxd + " " + gs.getMessage("Workflows for {0} have been cancelled", current.getDisplayValue()));
else if (numCnxd == 1)
gs.addInfoMessage("1 " + gs.getMessage("Workflow for {0} has been cancelled", current.getDisplayValue()));
}