Set change request as Rejected if user rejects an approval after it was previous approved by him

razvan1
Giga Contributor

Hello,

I'm trying to solve this and I can't get a solution: for a change request, if an user from approval group approve it, the workflow will continue with the next steps, but if the user reconsider his decision and Reject it, then the change will be set as 'rejected' and it will be closed.

I tried with a business rule on table "sysapproval_approver", on Change, if the State changes from 'Approved' to 'Rejected' and to use a script to identify the change number and set the approval state from 'Approved 1' to 'Rejected'.

myFunction();

function myFunction() {

  var changeNo = current.sysapproval;

  var gr = new GlideRecord('sysapproval_approver');

  gr.addQuery('sysapproval',changeNo);  

  gr.query();

  while (gr.next()) {

                    gr.sysapproval.approval ='Rejected';

                    }

  gr.update();

}

CaptureIMG.JPG

Thank you in advance!

1 ACCEPTED SOLUTION

razvan1
Giga Contributor

I managed to solve this:



myFunction();



function myFunction() {


  var changeNo = current.sysapproval.sys_id;


  //gs.addInfoMessage('Change no: '+changeNo);


  var gr = new GlideRecord('change_request');


  var statul;


  gr.addQuery('sys_id',changeNo);  


  gr.query();


  while (gr.next()) {


                            // gs.addInfoMessage(gr.approval);


                                  gr.approval ='Rejected';


                                  gr.update();


                            // gs.addInfoMessage(gr.approval);


    }


}


View solution in original post

7 REPLIES 7

marcguy
ServiceNow Employee
ServiceNow Employee

hi, the problem with this is that the workflow has moved on, so you will need to 'regress' the workflow as well, by either restarting or killing the workflow or having a workflow broadcast an event to make it rewind back.



So it's more work involved than simply reversing the 'approval' status field. I would ask how many times this would actually happen?


razvan1
Giga Contributor

Hi,


Thanks for you reply, the problem is not how many times it would happen, it is a SOX requirement so one time is enough


marcguy
ServiceNow Employee
ServiceNow Employee

understood, in which case your going to have a look at also restarting the workflow and in effect reversing the change back into approval phase etc, there are quite a few things to think about, with a few different options.



you could put the change on hold, back to draft, as i say quite a few options and would advise discussion with the process owners.


Kalaiarasan Pus
Giga Sage

I should say that it's a bad way of implementing a change management system.. Without proper investigation and analysis, why should the change be approved and then rejected ? Isn't this a process issue rather than related to tool?