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

razvan1
Giga Contributor

I don't have a clear answer. I'm a developer and for me it is only a task received from Management.


We should not be blind in implementing anything just because it is possible to do so and should always advise back things to improve process wherever possible.. Can't this be handled by a supervisory approval of some kind ? It would be much easier plus would be much more robust approach, process wise too


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);


    }


}