Allow only excel files as an attachment.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2023 06:28 PM
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
Could some please help?
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2023 06:44 PM - edited 12-14-2023 06:49 PM
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
Please mark my answer correct & helpful, if it helps you
Thank you
Thank you
G Ramana Murthy
ServiceNow Developer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2023 07:07 PM
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:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2023 07:47 PM
Please discard my posting. I have found the answer in the following link:
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2023 07:49 PM
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