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

Harsh Vardhan
Giga Patron

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);


  }

 

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.

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

find_real_file.png

 

find_real_file.png

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

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

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