How to trigger Business rule on sysapproval with multiple records?

Manuel27
Tera Expert

Hello Dev Friends,

I have a business rule running on the sysapproval_approver table that is triggered by 2 approval records to individual users that are approving the same record. Both users are required to approve the record. How can I add a condition to not have the business rule trigger unless BOTH of the approval records are state=approved?

Currently, as long as one is approved, the business rule triggers and cancels the other approval record due to the business rule's action is closing the parent Case which then cancels the second approval. 

I have posted the BR script, any recommendations/help with be appreciated.

 

Thank you, 

 

Conditions :

WHEN: After | update

State - Changes to - Approved

Source table - is - sn_hr_le_case

Approval for.HR Case.HR Service = "Offboarding" 

(function executeRule(current, previous /*null when async*/) {

	var gr = new GlideRecord('sn_hr_le_case');
	gr.addActiveQuery();
	gr.addQuery('hr_service','9fc5f3af1b6f24100888ed7bbc4bcba2');
	gr.addQuery('sys_id',current.sysapproval);
	gr.query();

	while(gr.next()){
		gr.setValue('state', '3'); //3 = closed complete
		gr.update();
			
	}

})(current, previous);
1 ACCEPTED SOLUTION

rldejesusm
Mega Guru

Hi Manuel,

 

I strongly recommend you use Approval Rules of the Approving Record for this purpose, instead of hooking up your custom BR straight in to sysapproval_approver table, you change the approval rules to say everyone needs to approve this record before it gets approved, and then your custom BR can be put to run once the Approving Record is approved.

Let me know if this works!

Good luck!

View solution in original post

1 REPLY 1

rldejesusm
Mega Guru

Hi Manuel,

 

I strongly recommend you use Approval Rules of the Approving Record for this purpose, instead of hooking up your custom BR straight in to sysapproval_approver table, you change the approval rules to say everyone needs to approve this record before it gets approved, and then your custom BR can be put to run once the Approving Record is approved.

Let me know if this works!

Good luck!