- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2025 10:31 PM
Hi All
Had a query regarding 'Add Attachment'. We need to restrict user from submitting form if more than 3 attachments are submitted.
My queries:
- Can we use the OOB Add Attachment for this case? How?
- Tried enabling 'Hide Attachment' checkbox and created a variable of type 'Attachment'. Wrote a Catalog Client Script to check length and throw error message. But in form itself after uploading one attachment, second attachment cannot be added. 'Updating the attachment will delete the previous attachment permanently. Do you want to continue?' getting this error.
Please help with some solution.
Thanks!!
#catalog
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2025 11:17 PM
yes it's a standard message which is shown.
The script I shared should work fine in both native + portal.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2025 03:52 AM
Hi
Thanks for the help!
Just tried the code, with a bit of tweak. Changed a bit and it worked.
Sharing below
function onSubmit() {
//Type appropriate comment here, and begin script below
var getAttach = this.document.getElementsByClassName('get-attachment').length;
//alert(getAttach+"length is");
if (getAttach > 3) {
g_form.addErrorMessage("Maximum number of attachment is 3");
return false;
}
}
Thanks @Ankur Bawiskar
Cheers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2025 10:45 PM
Don't use Attachment variable, it supports only 1 file at a time
You can use OOB paper-clip icon and check how many files attached
Use onSubmit catalog client script which applies to catalog item
function onSubmit() {
//Type appropriate comment here, and begin script below
try {
if (window == null) {
// portal
if (this.document.getElementsByClassName('get-attachment').length > 3) {
alert('You can attach max 3 files.');
return false;
}
}
} catch (ex) {
// native view
var length = getSCAttachmentCount();
if (length > 3) {
alert('You can attach max 3 files.');
return false;
}
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2025 10:56 PM
Thanks for the reply!
I had tried the given code, but it is throwing this info message of:
'This catalog client script is not VA supported due to the presence of the following variables in the script: window, this.document.getElementById.length, getSCAttachmentCount'.
Is it because of any scope restrictions as we are using this inside a custom scope.
Let me know if anyone has a solution.
Cheers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2025 11:17 PM
yes it's a standard message which is shown.
The script I shared should work fine in both native + portal.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2025 03:52 AM
Hi
Thanks for the help!
Just tried the code, with a bit of tweak. Changed a bit and it worked.
Sharing below
function onSubmit() {
//Type appropriate comment here, and begin script below
var getAttach = this.document.getElementsByClassName('get-attachment').length;
//alert(getAttach+"length is");
if (getAttach > 3) {
g_form.addErrorMessage("Maximum number of attachment is 3");
return false;
}
}
Thanks @Ankur Bawiskar
Cheers