How to set 5 attachments mandatory in before insert business rule in for change request

Dasari Srihari
Tera Contributor

Hi All,

 

How to set 5 attachments mandatory in business rule. i

1 ACCEPTED SOLUTION

Kalyani Jangam1
Mega Sage
Mega Sage

Hi @Dasari Srihari 

Use Below code in before insert rule for change request

 

(function executeRule(current, previous /*null when async*/ ) {
 
var gr = new GlideRecord("sys_attachment");
gr.addQuery("table_name", "change_request");
gr.addQuery("table_sys_id", current.sys_id);
gr.query();
var num = gr.getRowCount();
if (num < 5) {
gs.addErrorMessage("5 attachment File Mandatory for creating Change Request");
current.setAbortAction(true);
}
})(current, previous);
 
Please try and Mark Helpful and Correct if it really helps you.

View solution in original post

6 REPLIES 6

Hi @Ankur Bawiskar , Implemented same script. i have attached 6 documents still getting error.

 

 

var rec = new GlideRecord('sys_attachment');
	rec.addEncodedQuery("table_sys_id", current.getUniqueValue());
	rec.query();
	var count = rec.getRowCount();

if(current.category == 'CSOC' && current.u_sub_category == 'Create, Modify or Delete Rules or Playbook - CSOC' || current.u_sub_category == 'Onboard New Data or Log Source Type - CSOC' || current.u_sub_category == 'Create, Update or Delete Event Filtering - CSOC' || current.u_sub_category == 'Sentinel Administration or Change Configuration - CSOC' || current.u_sub_category == 'Install, Update or Uninstall Content Hub - CSOC' && count <1 ){
			gs.addErrorMessage('There is no attachment, Please attach Email attachment from Team Manager and respective Team Head');
			current.setAbortAction(true);
		
	}

else if(current.category == 'Network' || current.category == 'Network Security' || current.category == 'Systems' || current.category == 'Systems Security' || current.category == 'Cloud' && current.u_sub_category == 'CL - Grant, Modify, Revoke Access - Custom' || current.u_sub_category == 'CL - Grant, Modify, Revoke Access - Standard' || current.u_sub_category == 'Grant, Modify, Revoke Access - Standard' || current.u_sub_category == 'Grant, Modify, Revoke Access - Custom' && count < 5){		
		
			gs.addErrorMessage('Please attach this attachments 1.Managers Approval email attached'+ " "+ "2. BGV details attached"+ " "+ "3.SF training completion attached"+ " "+ "4.Policy acceptance attached"+" "+ "5.Matrix manager approval");
			current.setAbortAction(true);	
		
	}

 

 

@Dasari Srihari 

I believe I have shared script which should work fine. Also mentioned that you need to check the field name and choice values during comparison.

The further analysis and debugging can be handled by you.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader