The CreatorCon Call for Content is officially open! Get started here.

How to check for attachments on catalog item in client script?

e_wilber
Tera Guru

I can't seem to get any solution I've seen on here work.

 

The latest one I've tried is:

	if (this.document.getElementsByClassName('get-attachment').length == 0) {
		g_form.addErrorMessage(getMessage('attachment_mandatory'));

		return false;
	}

and I get the error: onSubmit script error: TypeError: Cannot read properties of null (reading 'document'):
function () { [native code] }

 

This catalog item is in a scoped application - is this likely what my problem is? If so, how can I replicate this for my scoped application so this works? 

2 REPLIES 2

Robbie
Kilo Patron
Kilo Patron

Hi @e_wilber,

 

Check out the below article from Ankur providing steps to implement including screenshots.

 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Helpful.

 

Thanks, Robbie

 

https://www.servicenow.com/community/developer-blog/verify-mandatory-attachments-count-on-catalog-it... 

RyanQ
Tera Contributor