Reset Change - UI Action not working correctly

Sam Ogden
Tera Guru

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.

find_real_file.png

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

 

16 REPLIES 16

Michael Fry1
Kilo Patron

In the business rule - SNC Approval - Reset Conditions - you didn't define a reset condition in the function checkResetConditions() {

You need to add something like:

    if (current.state.changesTo("-5"))

That's the trigger for the business rule to execute the lines under #1

Hi Michael,

Thanks for the above, however the condition on the business rule is:

current.approval.changesTo('Reset') && gs.hasRole('itil')

The UI action changes the approval field to 'Reset' so the business rule should then run.

As mentioned it is resetting the workflow, but since the upgrade it seems to push it onto the next action before resetting?

Thanks

Sam

For a normal business rule, that would work. For this business rule, you need to add the trigger condition to the Reset function.

Hi Michael,

How come we need to do this for this business rule?

The business rule does seem to be running as the approvals do get reset and it does eventually reset the workflow.  Is it just a certain part of that business rule that is not running?

Is this a change since Helsinki? as prior to our recent upgrade this worked and we had no changes in the business rule?

Apologies for all the questions, just trying to improve my understanding.

Thanks

Sam