How to make attachment mandatory for catalog item on the basis of a varibale value?

ads
Tera Expert

Hi All,

I have a select box type varibale called Request required, If the varibale value is Manage documnet,then the Add attachment will be mandatory with a message, I have ceated a onsubmit client script with the below script, I am able to show the message, but not the able to make attachment mandatory,

 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

if((g_form.getValue('request_required') == 'Manage document') && this.document.getElementsByClassName('get-attachment').length == 0) {
g_form.addErrorMessage(getMessage('attachment_is_mandatory'));

return false;

}
}

Can anyone help me out on this.

@Ankur Bawiskar 

1 ACCEPTED SOLUTION

@ads 

I created blog few years ago; check that and enhance it further

Verify Mandatory Attachments Count on Catalog Item 

ensure you use correct choice value for Manage document

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;
			}
		}
	}
}

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

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

View solution in original post

7 REPLIES 7

@ads 

the script should work the same irrespective of any user due to role etc there should not be an issue

share your latest script and screenshots

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

Hi Ankur,

 

Is there a way we can restrict the size of attachments for a catalog item on portal. So users would not be able to submit the record.

 

Regards,

Rahul

ads
Tera Expert

@Ankur Bawiskar  - Hi, Apologies, this one is working, I got issues with the below post's question.

https://www.servicenow.com/community/itsm-forum/how-to-create-the-advance-user-criteria/m-p/2447885#...