- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Tuesday
Hi,
So I know there are numerous solution available so please refrain from quoting another post or pasting links.
I have a requirement where I have to make sure that only PDF and JPG files are attached on the 'Add Attachment' in my catalog item.
It can be done using the following script
function onSubmit() {
//Check and see if there is atleast one attachment, if none, attachment is undefined
if (this.angular.element("#sc_cat_item").scope().attachments !== undefined) {
//Get the array of objects, each attachment has it's one object with data in the array
var attachArr = this.angular.element("#sc_cat_item").scope().attachments;
//If we find a PDF-file, let the user submit
if (attachArr.map(function (attach){return attach.ext}).indexOf('pdf') >= 0 ){
return true;
}
}
//If there isn't any PDF attached, dont let them submit it.
alert('You need to attach an PDF-file to be able to submit.')
return false;
}
This should work but the issue is, it is using DOM and ServiceNow does not promote using DOM in service portal.
Is there a way to do this using script include?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Tuesday
No solution without DOM is available
Only approach is to use Variable of type Attachment and then add attributes in that variable
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Tuesday
I also have the same opinion @Ankur Bawiskar . I was just looking for an alternative just in case.
Thank you for clarifying
