Restrict file attachment types in single catalog item
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
I'm trying to figure out how to write an onSubmit script to restrict attachment types to the following file types in a single catalog item using the built-in attachments icon (not the variable):
pdf,zip,txt,doc,docx,dwg,gif,csv,xls,xlsx,ppt,xml,xsl,bmp,html,png,pptx,cfr,jpeg,mp4,mov,odt,ods,odp,jpg,jpeg,rtf,wmv,wm,wma,heic,msg,jfif
I have found some older posts here but they don't seem to address multiple file types.
Thank you for any help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
then no direct way available but you need to use DOM manipulation
I used something similar in past and it worked fine for me.
It gave me array of file names in both native + portal
Based on that you can enhance the logic
Ensure "Isolate Script" field is marked as False for your client script
function onSubmit() {
//Type appropriate comment here, and begin script below
var arr = [];
var hiddenVariable = g_form.getValue('hidden_variable');
try {
if (window == null) {
// portal
var z = this.document.getElementsByClassName("get-attachment ng-binding ng-scope");
var k;
for (k = 0; k < z.length; k++) {
var value = z[k].innerHTML;
value = value.substring(0, value.indexOf('('));
arr.push(value.trim());
}
// now check if the allowed file name is present in the array or not
}
} catch (ex) {
// native get all the file names native
$j("a.content_editable").each(function(index) {
var val = $j(this).text();
arr.push(val);
});
// now check if the allowed file name is present in the array or not
}
}
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
it gave me file names in portal
I believe you can take it further from here.
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
