HOw to stop UiAction script if date fieds is empty

wakespirit
Kilo Guru

Dear all,

When I create a new change request, and I click on the UI Action button Request Approval, I would like to add in the button script the following statment :

If Start and End Date are empty then I shouldd display a error message and abort the Request Approval process

Any idea how to do ?

regards

1 ACCEPTED SOLUTION

Alikutty A
Tera Sage

Try this once from your UI action after deactivating the business rule

if (current.start_date==""){
 gs.addInfoMessage("Start date should not be empty");
 return false;
}else if(current.end_date==""){
 gs.addInfoMessage("End date should not be empty");
 return false;
}else{
//DO SOMETHING
}

View solution in original post

3 REPLIES 3

venkatiyer1
Giga Guru

You would need to write a client to validate those fields and return false to stop the ui action to proceeding further. For more help check out this link

https://www.servicenowguru.com/system-ui/ui-actions-system-ui/client-server-code-ui-action/

 

I have build a business rule for that as below :

if (current.start_date==""){
		gs.addInfoMessage("Start date should not be empty");
		current.setAbortAction(true);
	}
		
	if (current.end_date==""){
		gs.addInfoMessage("End date should not be empty");
	current.setAbortAction(true);
	}

which execute Before Update.

Error message is seen on the top of the, but my Request State still goes to teh next state, how to get back to current edition state before clicking on Ui Action Approval request ?

regards 

Alikutty A
Tera Sage

Try this once from your UI action after deactivating the business rule

if (current.start_date==""){
 gs.addInfoMessage("Start date should not be empty");
 return false;
}else if(current.end_date==""){
 gs.addInfoMessage("End date should not be empty");
 return false;
}else{
//DO SOMETHING
}