Allow only excel files as an attachment.

Annie10
Tera Contributor

Hello,

I have attachment type variable on the RITM that I would like user to attached only excel file to the record. If other file type is selected as an attachment, then it should show pop-up message

 

Annie10_0-1702607155336.png

Could some please help?  

Thank you

 

8 REPLIES 8

RAMANA MURTHY G
Mega Sage
Mega Sage

Hello @Annie10 ,

you can use below code snipped in onSubmit client script 

 

//for non-portal
var sysid =g_form.getElement('sysparm_item_guid').value;
// alert('sysid is  ' + sysid); 

var attachment = new GlideRecord("sys_attachment");
attachment.addQuery("table_name", "sc_cart_item");
attachment.addQuery("table_sys_id", sysid);
attachment.query();
var attachCount= attachment.rows.length;
if(attachCount!= 1)
{
if(attachCount==0)
alert("Attachment Required!!");
return false; 
}
else if(attachCount== 1 && attachment.content_type.indexOf(".xlsx") <= -1){
alert(attachment.content_type);
alert("Attachment should be in only xlsx format!");
return false; 
}
else
{
return true;
}

 

 

You can also refer below community link

https://www.servicenow.com/community/developer-articles/to-allow-attachments-of-specific-file-type-o...

 

 

Please mark my answer correct & helpful, if it helps you

Thank you

 

 

Please mark my answer helpful  & correct if it helps you
Thank you

G Ramana Murthy
ServiceNow Developer

Hello @RAMANA MURTHY G 

I used your suggested code, but it is still allowing me to attached other type of file.  Just wanted to be clear, the code must validate the "attachment type" variable not the attachments with the paper clip icon:

Annie10_0-1702609611207.png

 

Annie10
Tera Contributor

Please discard my posting.  I have found the answer in the following link:   

https://www.servicenow.com/community/developer-forum/how-to-validate-attachment-to-accept-only-jpg-f...

 

Thank you

Danish Bhairag2
Tera Sage
Tera Sage

Hi @Annie10 ,

 

Please read this KB article from servicenow. Configuration are mentioned

 

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0718013

 

Thanks,

Danish