How to check attachment before on submit client script in catalog item

dheeru_1994
Tera Contributor

Hii All 
i am writing this script in catalog item to know that item has attachment attached or not  on submit client script but 
error getting 
below is the code 

 

 

 

function onSubmit() {
    // Check if attachments exist
    var attachment = g_form.getAttachmentList();
    
    if (attachment.length > 0) {
        // If attachments are found, allow submission
        alert('Attachments found.');
        return true;
    } else {
        // If no attachments found, prevent submission and prompt user
        alert('Please attach a file.');
        return false;
    }
}

 

 

 

 

when i order item   error occure  Error MessageonSubmit   script error: TypeError: g_form.hasAttachmentList is not a function:
function () { [native code] }
glide record and script include not to use  is here anyone who can solve the issue now 


1 ACCEPTED SOLUTION

HI @dheeru_1994 please try to second approach

Script: onSubmit

Note: Ensure Isolate Script field is set to False for this Catalog Client Script to ensure DOM manipulation works

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

var countRequired = 1;
	if(window == null){
		// portal
		if(this.document.getElementsByClassName('get-attachment').length != countRequired) {
			alert('You must add 1 attachments before submitting this request.');
			return false;
		}
	}
	else{
		// native view
         var length = $j("li.attachment_list_items").find("span").length;
		if(length != countRequired){
			alert('You must add 1 attachments before submitting this request.');
			return false;
		}
	}
}

RamSingh_0-1712748080181.png

 

Please mark reply as Helpful/Correct, if applicable. Thanks!

 

View solution in original post

7 REPLIES 7

@dheeru_1994  did you get the solution of this? I also have similar requirement and don't see any option.

 

 

Alp Utku
Mega Sage

You can use out of box "Mandatory Attachment" checkbox under Portal Settings tab of Catalog Items. 

 

You don't need to write code for this. 

ChandanKuma
Tera Contributor

Is there any way of doing it without DOM manipulation and with GlideAjax