- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2025 02:10 AM
Hi Everyone,
I have a requirement where users must upload at least 2 attachments before submitting a service (Catalog Item / HR Service).
For example, if a user adds only one attachment, they should not be able to submit the request.
If anyone has done this before, could you please share a sample script or the best approach?
Thanks in advance,
Gokul
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2025 02:55 AM
this will work in both native + portal for record producer
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 must add 3 attachments before submitting this request.');
return false;
}
}
} catch (ex) {
// native view
var length = getSCAttachmentCount();
if (length < 3) {
alert('You must add 3 attachments before submitting this request.');
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
10-08-2025 03:00 AM
Hi Gokul,
Are the attachments well-defined. For example, they must attach a letter, and a photograph of a document? If so, I would recommend using the attachment variable/question type so the user is guided to what attachments are required. Requiring 2 documents can lead to a user simply uploading the same attachment twice.
https://www.servicenow.com/docs/csh?topicname=attachment.html&version=latest
