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

ricker
Tera Guru

SandyL83,

It looks like this rule is running on the sysapproval_approver table.   There is nothing here that would prevent the creation of an approval record...it sets the state and adds comments.  I don't think you should stop the creation of the approval record at this point....It would probably cause issues with the approval.  If you want to prevent the creation of the 2nd approval you have find where in your process it's being created and prevent it from being created using your same logic.

Hi, thank you for responding. 

To clarify, prior to implementing the business rule, it was functioning like this:

1st approval: Person A

2nd approval: Person A

 

So to solve for that, and only require Person A to approve once, I did the business rule so that the 2nd Approval record for Person A would still be generated, but that record would be automatically approved since they already approved in the previous step. 


After the business rule,  it looks like this -

1. Approval for person A

After Person A approves:

2. Approval record for Person A - auto approve with comments

3. Approval record for Person A - auto approve with comments

 

so it is auto approving the 2nd one, but it's creating 2 records for some reason. 

 

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?

thanks again.. it is very strange.. I did confirm there is not a 3rd approval and I tried grAppr.  I am pretty certain nothing else is creating the approval because when I make the business rule inactive, the approval goes away. 

thanks for you help!