- 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 01:40 AM
Hello @AnilJ ,
Below link should be able to help you:
https://www.servicenow.com/community/itsm-forum/check-attachment-file-type-client-script/m-p/619137
If my answer has helped you in any way please mark it as correct or helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2025 01:43 AM
Hi @AnilJ ,
Try below onSumbit catalog client script.
function onSubmit() {
// Get the file upload variable (replace 'file_variable_name' with the actual name of the file upload variable)
var fileVar = g_form.getValue('file_variable_name'); // Ensure this is the variable name of your file upload field
// Check if a file has been uploaded
if (fileVar) {
// Get the file extension (get the part after the last dot in the filename)
var fileExtension = fileVar.split('.').pop().toLowerCase();
// If the file extension is not '.msg', show an error message
if (fileExtension !== 'msg') {
g_form.showFieldMsg('file_variable_name', 'Please upload a valid .msg file.', 'error');
return false; // Prevent form submission
}
}
// If the file is valid, allow the form submission
return true;
}
Please mark as Correct/helpful or accepted solution if it solves your issue.
Best Regards,
Pooja
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2025 02:19 AM
variable attributes should work
share what did you configure and what's not working?
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 02:55 AM