Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

make attachment mandatory

snowsid88
Tera Contributor

Write code to make attachment mandatory if priority is critical and state changed to resolved in Incident table.

 

Please suggest.

7 REPLIES 7

Dr Atul G- LNG
Tera Patron

Hi @snowsid88 

Did you try using a UI Policy? It's low-code and easy to implement

 

https://www.servicenow.com/community/developer-articles/possible-ways-for-making-an-attachment-manda...

*************************************************************************************************************
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/dratulgrover [ Connect for 1-1 Session]

****************************************************************************************************************

Chaitanya ILCR
Giga Patron

Hi @snowsid88 ,

 

you can create a before update BR on the incident table

ChaitanyaILCR_0-1754058162478.png

with script

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

    var attachmentGR = new GlideRecord('sys_attachment');
    attachmentGR.addQuery('table_name', current.getTableName());
    attachmentGR.addQuery('table_sys_id', current.getValue('sys_id'));
    attachmentGR.query();

    if (!attachmentGR.hasNext()) {
        gs.addErrorMessage('Attachments are required when resolving a Critical incident.');
        current.setAbortAction(true);
    }

})(current, previous);

ChaitanyaILCR_1-1754058275781.png

 

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

Syed14
Giga Guru

You can create a business rule and add the below script.

Syed14_0-1754073236734.png

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

    if (current.hasAttachments() != true) {
        gs.addErrorMessage("PLease add an attachment");
        current.setAbortAction(true);
    } 

})(current, previous);

 

Mohammad Danis1
Giga Guru

Hi @snowsid88 
As suggested above, you can create a Before Update BR with the required conditions

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

	// Add your code here
	if(current.hasAttachments != true){
		gs.addErrorMessage("Attachment is mandatory.");
		current.setAbortAction(true);
	}

})(current, previous);

If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Mohammad Danish