Restrict on type of attachment attached

shweta32
Kilo Contributor

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. 

12 REPLIES 12

Adittyaa Varadk
Tera Contributor

Hi Shweta,

Did you find anything on this? Because I have same requirement but unable to find the solution.

Thanks & Regards,

Adittyaa

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.

Hi,

nice information.

Please share complete details so that it benefits members.

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

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

Thank you.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader