- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2025 01:03 AM
I have a requirement where there is an attachment type field(e.g., diso_approval) if it contains only .msg file then submit the request; otherwise unable to submit form.
Note: Variable Atrribute not working( Need a script).
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2025 03:08 AM
seems your form doesn't have that field
add this from list in the variable attributes for that variable allowed_extensions=msg
From list you can add if you don't want to make any form layout
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2025 03:08 AM
seems your form doesn't have that field
add this from list in the variable attributes for that variable allowed_extensions=msg
From list you can add if you don't want to make any form layout
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2025 03:29 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2025 02:37 AM
Hi
You can use Glide Ajax in Client Script and Script Include to get the attachment content type from sys_attachment form and compare the response. For .msg file the content type is application/vnd.ms-outlook
Please use below code and let me know if this works for you.
Create On Change Client Script for Attachment field.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var cartId = g_form.getParameter('sysparm_item_guid'); // finds the card id
var ga = new GlideAjax('AZFCMassHelper');
ga.addParam('sysparm_name', 'getAttachmentType');
ga.addParam('sysparm_cartID', cartId);
ga.getXMLWait();
var answer = ga.getAnswer()
if (answer != "application/vnd.ms-outlook") {
g_form.addErrorMessage('Only .msg file allowed. Attached file is: ' + answer);
return false;
} else return true;
}
Script Include
getAttachmentType: function() {
var cartid = this.getParameter('sysparm_cartID');
var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_sys_id', cartid);
gr.query();
if(gr.next())
{
return gr.content_type;
}
},
Please find below screenshot for reference:
Getting error file other file types
For .msg file attachment is allowed and no error is getting
Please let me know i this solution works for you and mark as "Accept/Helpful".
Regards,
Sourabh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2025 02:59 AM - edited 02-20-2025 03:00 AM
Hi, please try this solution, it should work for you,
function onSubmit() {
var fieldName = 'diso_approval';
var attachments = g_form.getValue(fieldName);
if (!attachments) {
return true;
}
var validFilePattern = /\.msg$/i; // Regular expression to validate .msg file
var attachmentList = attachments.split(',');
for (var i = 0; i < attachmentList.length; i++) {
var fileName = attachmentList[i].trim();
if (!validFilePattern.test(fileName)) {
return false;
}
}
return true;
}
If it helped you - please mark it as helpful answer,
Best regards,
Renat Akhmedov
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2025 03:37 AM
I used the above script and now I am getting the following error while uploading the .msg file.