business rules

Gaurav69
Tera Contributor

Hii, I have created 2 custom tables named as Accounts and External Accounts. External Accounts is in the related list of Accounts. I want to put a limit on the recors creation of external accounts. if it surpasses the limit of 4 records or more than 4 records are created on external accounts it should show me a warning and prevent me creating record. How to configure it?

Thanks in advance.

1 REPLY 1

Community Alums
Not applicable

Hi @Gaurav69 ,

Please create Before Business rule on Account table and try to add below code 

 

var accGr = new GlideRecord('u_account_external')// account table 
accGr.addQuery('parent', current.sys_id);
accGr.query();
var count = accGr.getRowCount();
if(count <= 4 ){
	if(accGr.next());{
		var accGrInsert = new GlideRecord('u_account_external');
		accGrInsert.initialize();
		accGrInsert.short_description = current.short_description;
		accGRInsert.insert();
	}
}else{
	gs.addErrorMessage('You can not create new create with this account');
	current.setAbortAction(true);
}

 

Note: Please change your fields value above as per your requirement

 

Please mark my answer correct and helpful if this works for you

 

Thanks and Regards 

Sarthak