UI Action works for Admin but not ITIL user

Sam Ogden
Tera Guru

Hi All,

One of my colleagues has added a new UI Action 'Reset Change Workflow' to our change Request form.   This is meant to allow users to reset the change back to draft at any stage of the workflow, and it will cancel all the approvals, and reset the workflow so any changes can be made and then it can be sent back round the workflow.

When we try the UI action as an Admin it is working and the log goes back to draft etc.   When we try with an ITIL user the UI action is there to select, but it is not performing the actions.

on a HI ticket they have mentioned they are seeing the following:


Uncaught ReferenceError: RiskAssessmentCalculator is not defined "

The UI action is set as:

find_real_file.png

find_real_file.png

And this uses the following 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;
}

1 ACCEPTED SOLUTION

Matthew Smith
Kilo Sage

Hi Sam



It might be something to do with ACLs. Check if there is anything on the change_request.state field and if so, try deactivating it.



Hope this helps.



Matt


View solution in original post

6 REPLIES 6

Stephen Whitney
Kilo Expert

Sam,



We have a UI Action that does something similar. In our Change workflow after a request has been approved we made the planned start and planned end dates read only and prior to the change request being implemented there is a UI Action (form button) that allows Itil users to change the planned start/end dates. Clicking on that UI Action reset the workflow for the change, cancels the approvals and puts the change request back in the "new" state. Here's the script we are using from the UI Action:



new Workflow().restartWorkflow(current, true);


new WorkflowApprovalUtils().cancelAll(current, 'Change to be rescheduled');      


current.state = "-5";


current.work_notes = "'Reschedule Change' button was selected";


gs.addInfoMessage('Update planned dates and re-route request for approval');


current.update();


action.setRedirectURL(current);



Reschedule_change.png



I hope this helps.


Matthew Smith
Kilo Sage

Hi Sam



It might be something to do with ACLs. Check if there is anything on the change_request.state field and if so, try deactivating it.



Hope this helps.



Matt


Thanks Matt,



We had a write ACL on the state field that only allowed write in certain states.



Sam


Stephen Whitney
Kilo Expert

Sam,


Just checking back to see if you're still having the issue. If so, have you tried updating the end of the condition to something like below?



".. || (current.type!='emergency' && gs.hasRole('change_manager'))"