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
06-07-2021 09:47 AM
Hi Shweta,
Did you find anything on this? Because I have same requirement but unable to find the solution.
Thanks & Regards,
Adittyaa
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2021 08:47 PM
Hi Aditya,
Yes, I was able to implement this. Within UI policies, there is a policy 'GlobalCatalogItemFunctions'. Within it add below function :
function getSCAttachmentType() {
var fileExtension;
try {
var attachments = this.angular.element("#sc_cat_item").scope().attachments;
for (var x in attachments) {
fileExtension = attachments[x].ext;
}
} catch(e){
fileExtension = 'Error in type';
}
return fileExtension;
}
And call function getSCAttachmentType() in your client script to get the extensions of the file and based on which you can apply your conditions.
eg : var type = getSCAttachmentType(); //here type will provide you file extension
In case policy GlobalCatalogItemFunctions does not exist, create one and map it
Portal -> portal you are using -> Theme -> JS Include. Add this within JS include.
Please let me know if this works for you and mark it as correct.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2021 09:42 PM
Hi,
nice information.
Please share complete details so that it benefits members.
Regards
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
06-08-2021 10:19 PM
Hello Ankur,
Thank you!
Above is complete information. I have used the function is my On Submit client script as :
var extension = getSCAttachmentType();
if((extension.indexOf('xlsx') > -1) || (extension.indexOf('xls') > -1)){
return true;
else
return false;
This is the complete functionality that I have used to make it work. Along with function getSCAttachmentType() created in UI policy GlobalCatalogItemFunctions which is mentioned in my above comment.
Please let me know if you face any difficulty while implementing this, will be happy to assist.
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2021 11:02 PM
Thank you.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader