Need Help with Business Rule condition

geet
Tera Guru

Hi,

 

geet_0-1695271902387.png

I have a BR where I am trying to abort the submission if user has selected Yes is approval required but has not selected one of the approval.
User should either select user approval or group approval. If none is selected it will abort action.
Here is the code. BR is acting strange as I think my condition is not correct. It is only allowing submission when both checkboxes are checked.

Please guide.

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

	// Add your code here
	
	var ApprovalRequired = current.approval_required;
	gs.info(ApprovalRequired);
	var userApproval = current.user_approval;
	var groupApproval = current.group_approval;
	if(ApprovalRequired == 'yes' && (userApproval == '' || groupApproval == '')){
		
		
			gs.addErrorMessage("Please select either User or Group Approval when Approval required is selected as Yes");
			current.setAbortAction(true);
		
	}

})(current, previous);

 

1 ACCEPTED SOLUTION

RAMANA MURTHY G
Mega Sage
Mega Sage

Hello @geet ,

 

You need to change 

 

 

if(ApprovalRequired == 'yes' && (userApproval == '' || groupApproval == '')){

 

this statement as below

 

if(approval == 'Yes' && !(userApprove == true || groupApprove == true)){

 

 

You can achieve the same without using a script, please find below screenshots

 

RAMANAMURTHYG_1-1695274306724.png

 

 

RAMANAMURTHYG_0-1695274247377.png

 

 

Please mark my answer helpful, if it helps you

Thank you

 

 

 

Please mark my answer helpful  & correct if it helps you
Thank you

G Ramana Murthy
ServiceNow Developer

View solution in original post

6 REPLIES 6

soumyagupta
Tera Contributor

Hi, 

Please try below code:

 

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

	// Add your code here
	
	var ApprovalRequired = current.approval_required;
	gs.info(ApprovalRequired);
	var userApproval = current.user_approval;
	var groupApproval = current.group_approval;
	if(ApprovalRequired == 'yes' && ( !userApproval && !groupApproval )){
		
		
			gs.addErrorMessage("Please select either User or Group Approval when Approval required is selected as Yes");
			current.setAbortAction(true);
		
	}

})(current, previous);

 

 

Please mark correct if it resolves your query.

 

Regards,

Soumya

Any update on this?