- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2024 07:48 PM
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
Solved! Go to Solution.
- Labels:
-
Benchmarks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2024 04:21 AM
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; } } }
Please mark reply as Helpful/Correct, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2024 08:45 PM - edited 04-09-2024 08:56 PM
Hi @dheeru_1994
(A)Try to this code
function onSubmit() {
//Type appropriate comment here, and begin script below
var count = getSCAttachmentCount();//Checking attachment count.
if(count <= 0) {
alert('You must attach this item');//If there is no any attachment, it will show alert message and abort to submit form.
return false;
}
}
Second Approach
(B) For example: You need to ensure there are exact 1 attachment added before submission
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;
}
}
}
Isolate Script: Set to False
Please mark reply as Helpful/Correct, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2024 10:09 PM
function onSubmit() {
//Type appropriate comment here, and begin script below
var count = getSCAttachmentCount();//Checking attachment count.
if(count <= 0) {
alert('You must attach this item');//If there is no any attachment, it will show alert message and abort to submit form.
return false;
}
}
this is not working error giving

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2024 04:21 AM
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; } } }
Please mark reply as Helpful/Correct, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2024 05:38 AM
i can not use dom manipulation now how can i achieve this here