- 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-12-2025 03:55 AM
Glad to know.
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 04:01 AM
Seems you marked your own response as correct.
Would you mind marking my response as correct as my script worked for you?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader