How to make attachment mandatory

Community Alums
Not applicable

Hello ServiceNow Family,

Good day!

 

How to make attachment mandatory for a specific choice(Choice 2) in a catalog item.

But for other choices this should not be a mandatory.

Please help...

 

Thanks,

Rajesh

2 REPLIES 2

Dr Atul G- LNG
Tera Patron
Tera Patron

 Hi @Community Alums 

 

Exact you looking for

https://www.servicenow.com/community/developer-forum/can-i-make-add-attachment-mandatory-based-on-variable-question/m-p/1431465

 

credits @Ankur Bawiskar 

 

function onSubmit() {
	//Type appropriate comment here, and begin script below

	var countRequired = 1;
	if(g_form.getValue('request_required') == 'Manage document'){
		if(window == null){
			// portal
			if(this.document.getElementsByClassName('get-attachment').length != countRequired) {
				g_form.addErrorMessage(getMessage('attachment_is_mandatory'));
				return false;
			}
		}
		else{
			// native view
			var length = $j("li.attachment_list_items").find("span").length;
			if(length != countRequired){
				g_form.addErrorMessage(getMessage('attachment_is_mandatory'));
				return false;
			}
		}
	}
}

https://www.servicenow.com/community/developer-forum/how-to-make-attachment-mandatory-for-catalog-item-on-the-basis/m-p/2456988 

*************************************************************************************************************
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
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/atul_grover_lng [ Connect for 1-1 Session]

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

Ankur Bawiskar
Tera Patron
Tera Patron

@Community Alums 

why not use Attachment type variable and make it mandatory based on the choice using Catalog UI policy?

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