Attachment verification for Catalog Items

Russell Abbott
Kilo Sage

It has been recommended to look into the script that we use to validate an attachment on a Catalog Item submitted both in Portal and ITIL views. Here's the script in question

function onSubmit() {
	var vpn_form = g_form.getValue('vpn_form_completed_standard_form');

	if(vpn_form == 'Yes'){
		//Works for native view
		try {
			var attachments = document.getElementById('header_attachment_list_label');
			if (attachments.style.visibility == 'hidden' || attachments.style.display == 'none' ) {
				alert('You may be missing an attachment, please attach and resubmit');
				return false;
			}
		}
		//For Service Portal
		catch(e) {
			var count = getSCAttachmentCount();
			if(count <= 0) {
				alert('You may be missing an attachment, please attach and resubmit');
				return false;
			}
		}
	}   
	else if (vpn_form == 'No'){
		alert('Please select YES for the variable VPN Form Completed : Standard Form, attach and resubmit');
		return false;
	}
}

It has been suggested to set Isolate to True, and to remove getElementByID and getSCAttachmentCount.

I found a way to remove getElementByID but not getSCAttachmentCount.

 

As far as I can see, not Isolating is necessary here.

 

Is there another way to validate an attachment on both Portal AND Itil without that?

 

Thank you in advance!

6 REPLIES 6

Brian Lancaster
Tera Sage

I believe it is only getElementByID that requires Isolate to be true. I'm curious what was the reason for the recommendation to look at the script?

Sorry, you are correct. It was in reference to getElementByID. A 3rd party suggests that "Trying to use them in Catalog Client Scripts where the UI Type is not "Desktop" may result in run time errors. It is recommended not to use jQuery, PrototypeJS, gel and other techniques"

 

Note, I don't have any issues with the script as it stands, these are suggestions for best practice from a 3rd party analysis.

That is true that this is best practice. Sometimes you cannot avoid using these things like in this situation. I use this same script for several catalog items. I love how these analysts make suggestions but don't give you anything on how to do it.

Completely understand, I couldn't find another efficient way to handle this, so that makes sense. I appreciate your feedback!