cancel all awaiting aprovals

Richard P
Mega Guru

It seems if a change is canceled that approvers still have an outstanding task to approve a job which approval is now no longer required.

I thought it would be a buisness rule, but that didnt seem to work.

can someone advise the best way that if a a change is canceled, we then change the state of all approvals to no longer required anc close all tasks related.

thanks

1 ACCEPTED SOLUTION

Hi,



I created a UI Action on the request item table to find and cancel outstanding approvals which is a pretty similar thing to what you're doing.



I used an if(approval.next) cos the existing BRs take into account the other approvals and mark them as not required....   It does highlight how to update the approval record though.... looks like you're referring to client script functions setValue(X,Y) etc etc



  approval.state = 'rejected';


  approval.comments = "Cancelled by " + user;


  approval.update();




Example Script


var user = gs.getUserDisplayName();



var approval = new GlideRecord('sysapproval_approver');  


      approval.addQuery('sysapproval', current.sys_id);


      approval.addQuery('state', 'requested');  


      approval.query();  



if(approval.next()){



  approval.state = 'rejected';


  approval.comments = "Cancelled by " + user;


  approval.update();


  gs.addInfoMessage("Request Item: " + current.number + " has been cancelled");




} else {


  gs.addInfoMessage("Request Item: " + current.number + " cannot be cancelled as there are no active approvals");


}//end else


View solution in original post

10 REPLIES 10

Abhinandan Pati
Giga Guru

Hi Richard,



May I know why business rules are not serving your purpose here? I think BR is the best solution for your requirement. Or you can add your logic in workflow itself.



Thanks


Abhinandan


Thanks for your interest Abhinandan, but I don't know exactly why they're not working.



using UI


if I have the table set at change for the BR them I can only change the state of the change record not the itterations of the approvals.



If I select the table approvals, the canceled state wont be triggered because its waiting for the approval cancel rather than the change cancel.



is what Im guessing at the moment.



I don't know how to have it change the "approval" state based on the "change "state within UI



I tried with a script I found, but that didn't seem to work either (i'm not ofet with Javascript, I can understand it if I read it, and make adjustments, but not yet able to write from scratch, so I usually steal scripts and modify for now).



If you could say how you would set it up, that would be helpful





kalp_d123
Tera Expert

Hello Richard,



Could you try below script, which will give you approval list for the respective change.


Modify script according to your needs and run this script in 'script - background' with elevated role.



var gr = new GlideRecord('change_request');


gr.addQuery('state', 'Cancelled'); // Check the Cancelled state


gr.query();


while(gr.next())


{


  var grApp = new GlideRecord('sysapproval_approver');


  grApp.addQuery('sysapproval',gr.sys_id);


  grApp.query();


while(grApp.next()){


// update the approval state here


}


  gs.log('The row count for this is '+grApp.getRowCount());


  }




Thank you,


Thanks Kalpesh



Ill give it a go, as said above I'm new to Javascript.



in the place you say


// update the approval state here


I assume I need something like



setValue('state', "No Longer Required');



but I know enough to know that it needs some sort of refrence to the actual state itteration its currently at



can you advise what that would be?


something like



setValue(gr.App.state, "No Longer Required');



also should the value be a string "no longer required" or the value of the string?