Skip Redundant approvals on RITMs

SandyL83
Tera Guru

Hello, 

I would like to skip redundant approvals on RITMs.

All of our RITMs currently go to the requested for manager to approve and from there, there are typically additional approvals. 

If one of those additional approvals is being routed to the person (typically the manager) who already approved, I would like to skip that.  So whether it's auto setting that 2nd approval to "no longer required", or not generating the approval at all.

Since I would like this for all RITMs, would this be best solved by a Business Rule?  Or specific  scripting within the flow (we are using flow designer). 

I found a post on ServiceNowguru.com, but it's pretty old and it recommend a business rule - so I followed the steps in this link and it did not work

https://servicenowguru.com/scripting/business-rules-scripting/prevent-redundant-approval-requests-se...

 

Any specific help would be greatly appreciated!

Thank you!

 

1 ACCEPTED SOLUTION

 

I think you have a mistake where you added the second line for the comments. Adding the second line requires you to have the curly brackets on the IF statement.

I also want to be sure that the business rule is a BEFORE with order 100 and only INSERT is selected (advanced view).

Another suggestion to figure out if everything works as desired is to add gs.log inside the code to understand why you are getting two records.

 

(function executeRule(current, previous /*null when async*/) {
	
	// current.approver is the sys_id of the person that you will be evaluating on whether to create the necessary approval or not.
	
	var gr = new GlideRecord('sysapproval_approver');
	gr.addEncodedQuery('state=approved^sysapproval='+current.sysapproval+'^approver='+current.approver); //all previuos approved approvals for the person on the RITM
	gr.query();
	
	if(gr.next()) {
	     current.state = 'approved';
             current.comments = "Automatically approved based on a previous approval on the same record by the same user.";
	}
})(current, previous);

 


If I helped you with your case, please click the Thumb Icon and mark as Correct.


View solution in original post

7 REPLIES 7

Give a try with two possibilities:

  • Make it BEFORE with order 1000. That should be after all the engines ran on it. Check this link for the execution order of scripts and engines.
  • If that doesn't get rid of the second record, try AFTER with order 100. The reason I originally said BEFORE it was because my initial intention was to not even create the approval record in the first place but you wanted to create it and then approve it so that changed the game.

If I helped you with your case, please click the Thumb Icon and mark as Correct.


Thank you! 

I realized I had a condition current.state.changesTo('requested') and once I removed that, the duplicate went away..

THank you for all of your help with this. 

 

Hello,

I thought I had this fixed but it looks like it's not. 

When I tested with a very basic RITM, it works perfectly... it creates the first approval, then the 2nd approval is generated and auto approved with comments, only 1 record. 

However, when I tested with one that is tied to a reusable flow, it's still generating the duplicate approval -- it's still auto approving and leaving the comments.. I have no idea why it is doing this. I think it's definitely due to a reusable flow that is linked to the item that drives the second approval, but I can't figure out why it would be doing that. 

Any ideas on how to troubleshoot this?

THanks again.