Auto Approve redundant approvals on RITMs

SandyL83
Tera Guru

Hello,

I posted something similar and got some really good feedback, and I think I have this 95% solutioned..

on our RITMs, if there are multiple approvals for the same person, we want to auto approve any subsequent approvals for that person -- for example, let's say  I am a person's manager so all RITMs go to the person's manager for approval. But maybe I am also an additional approver for that item.  If I've already approved, I'd just like to have to approve the first time, then when the second approval is generated, I'd like it auto approved with comments (saying it was auto approved..).

I've got it working except in my situation, after the first approval is manually approved, it's creating 2 approval records and automatically approving them (it should just be 1 approval record). 

I am doing via business rule - Before, Insert, 100. 

Here si the code to my business rule. Can anyone  see why this would be causing 2 approval records rather than 1 to be created and auto approved?

Thanks!

(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);
1 ACCEPTED SOLUTION

Thanks for clarifying.  That is odd.  I've heard using gr as a variable name can cause issues....maybe try grAppr instead.  You could also try putting the condition into a script include and condition field instead of in the script....Is there possibly a 3rd approval?  Are you positive nothing else is creating the approval?

View solution in original post

5 REPLIES 5

Hey just wanted to check back in!!!  I had the following condition:

current.state.changesTo('requested')

Once I removed that it stopped with the duplicate... thank you!!!!!!!!!!!!!!!!!!!!