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
08-18-2021 11:22 PM
Hi Shwetha,
I tried and replicated the same as you did, but its not working.
In js includes, its asking to create UI Script , so i have used your script in that and called that scrpt in onSubmit CS.
Could you please suggest me on this.
Many thanks in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2021 11:16 PM
Hi Shweta, Adittyaa,
Create one system property for types you want to allow in sys_properties table in that property put comma separated values of content type you want to allow. Content type you can get from sys_attachment table check for any existing attachment for .xls or .xlsx check the content type and put it in property you have created.
after that Create before insert business rule on sys_attachment table and put below code.
Note: Apply your table condition or any specific condition so that it will not run for other tables
var arr = gs.getProperty('property_name').split(','); //specify property name
if(!arr.indexOf(current.content_type.toString()) >= 0 )
{
gs.addErrorMessage('Selected file type is restricted');
current.setAbortAction('true');
}
Mark this correct/helpful if this helps you.
Thanks,
Akshay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2023 08:41 AM - edited 07-15-2023 08:42 AM
Hi Shweta,
An easy method to achieve the same is;
While creating a catalog item of type: 'Attachment', of the 'Type Specification' section in the field 'Variable Attribute', we can simply mention a line of code: allowed_extensions=xls;xlsx. This is what I found in ServiceNow docs: Service Catalog variable attributes
This will without any exclusive scripting do the work for us. It even presents an error message if another type of file is added other than the specified.
Please feel free to mark the answer helpful and correct.
Kind regards,
Soumya