Reset Change - UI Action not working correctly
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2018 07:08 AM
Hi All,
We have a related Link UI action called 'Reset Change Workflow' on the change_request form. This resets the workflow and approvals of the change_request and returns it to the state of 'draft' :
This uses the 'SNC Approval - Reset Conditions' Before Update Business rule:
// these are the conditions under which the change request approvals need to be canceled 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 = 'Approval reset by ' + gs.getUserDisplayName(); //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'
if (typeof GlideRecordLock != 'undefined')
chg_wf_lock = GlideRecordLock(current);
else
chg_wf_lock = new Packages.com.glide.script.RecordLock(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);
//
// 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);
//
}
//Use this section to reset any necessary information on the Change request
current.work_notes = 'Change approvals and workflow reset due to material change by ' + gs.getUserDisplayName();
current.approval = 'not requested';
//Use this section to reset any necessary information on any associated Change tasks
var tsk = new GlideRecord('change_task');
tsk.addQuery('change_request', current.sys_id);
tsk.query();
while(tsk.next()){
tsk.work_notes = 'Change request workflow reset.';
tsk.update();
}
gs.addInfoMessage('Change approvals and workflow reset for ' + current.number + '.');
}
function checkResetConditions() {
var doReset = false; //default to no reset
//add reset conditions here such as:
//if (current.assigned_to.changes())
doReset = true; //enable the reset
return doReset;
}
When we use this UI action it seems to push onto the next action of the workflow before resetting. This is leading to some approvals being added to the change even though it shouldn't have reached this point of the workflow yet.
As can be seen above, the change was at the Approval - Group 'Change Task Approval' stage when the UI action was selected. but it seems to have pushed onto the set values - approval and part way the to Approval Group - Change Manager Group Approval.
This has caused the Change Manager Group approval to be added. It has then reset the individuals approval requests (form the change manager group) in the approvers tab, but it has left the group approval still requested.
Any help on why this is happening?
Thanks
Sam
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2018 10:09 AM
Valid question but in using this in the past, I've never had luck with just adding conditions for this rule. So since SNC added all the comments, who reads comments, once I followed the instructions, works perfectly.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2018 10:15 AM
Thanks Michael.
I've added in a condition:
// these are the conditions under which the change request approvals need to be canceled 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 = 'Approval reset by ' + gs.getUserDisplayName(); //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'
if (typeof GlideRecordLock != 'undefined')
chg_wf_lock = GlideRecordLock(current);
else
chg_wf_lock = new Packages.com.glide.script.RecordLock(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);
//
// 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);
//
}
//Use this section to reset any necessary information on the Change request
current.work_notes = 'Change approvals and workflow reset due to material change by ' + gs.getUserDisplayName();
current.approval = 'not requested';
//Use this section to reset any necessary information on any associated Change tasks
var tsk = new GlideRecord('change_task');
tsk.addQuery('change_request', current.sys_id);
tsk.query();
while(tsk.next()){
tsk.work_notes = 'Change request workflow reset.';
tsk.update();
}
gs.addInfoMessage('Change approvals and workflow reset for ' + current.number + '.');
}
function checkResetConditions() {
var doReset = false; //default to no reset
//add reset conditions here such as:
if (current.state.changesTo("1"))
doReset = true; //enable the reset
return doReset;
}
Our first state is Draft (value = 1) which is what the UI action changes the state to, but I am still seeing the same results, so the workflow is not resetting straight away. It moves onto the next action before resetting causing additional approvals to be added before they get reset?
I'm not sure what part I'm missing in the business rule as looking at the steps at the top I think these are all covered now?
Thanks
Sam
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2018 10:35 AM
Just to add to this,
I've added a log statement in the checkResetConditions function and can see doReset is showing as true.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2018 10:36 AM
I went back and looked at your UI action. It's just setting the field, but not saving the form? is something else happening after the UI action is clicked?
For example, here is what our UI action looks like:
function changedates(){
var st = g_form.getValue('state');
g_form.setValue('state', -5);
if (g_form.getValue('comments') == '')
{
g_form.setMandatory('comments', true);
g_form.showFieldMsg('comments','Comments are mandatory to change Planned Dates','error');
alert("Comments are mandatory to change Planned Dates");
return false; //Abort submission
}
var answer = confirm('Changing the Planned Dates will delete all existing approvals, continue?');
if(answer != true){
g_form.setValue('state', st);
return false;
}
gsftSubmit(null, g_form.getFormElement(), 'planned_dates');
}
if (typeof window == 'undefined')
serverResolve();
function serverResolve(){
current.state = -5;
current.update();
action.setRedirectURL(current);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2018 02:50 AM
Hi Michael,
is that not what line 6 is for:
gsftSubmit(gel('sysverb_update_and_stay'));
I believe that the UI action was copied from the SN Guru site.
Obviously this is fairly old on the site and seems not fully compatible with Kingston.
Thanks