Restrict on type of attachment attached
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2019 12:59 AM
Hello,
I have a requirement in which I need to allow only attachments with extension .xls or .xlsx and this needs to be done only for a particular catalog item.
Kindly suggest.
- Labels:
-
Scripting and Coding
-
Team Development

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2019 01:06 AM
create before insert business rule on sys_attachment table.
business rule condition : current.table_name == 'your table ';
script:
var fileName = current.file_name.toString();
if(fileName.indexOf(".xls") != -1 || fileName.indexOf(".xlsx") != -1 ){
gs.addInfoMessage("The File should be xls or xlsx file");
current.setAbortAction(true);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2019 11:24 PM
Hi Harshvardhan,
Thank you!
Can we have something in onSubmit script for the check?
Like : var count = getSCAttachmentCount(); through this we can get number of attachments attached on the form.
and document.getElementById('header_attachment_list_label'); through this ID for the attachement.
I tried using document.getElementByName but didn't work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2019 11:48 PM
Hi Shweta,
document.getElementById won't work in Service portal or native UI as well
try using business rule approach
business rule: before insert; condition as per screenshot
in actions tab: abort action and the message
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2019 11:41 PM
Hi Shweta,
Any update on this?
Can you mark my answer as ✅ correct, 👍 helpful if you were able to achieve the requirement. This helps in removing this question from unanswered list and helps users to learn from your thread. Thanks in advance.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader