- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2025 08:51 AM
Hi @D V Sandeep , Did you check the console what error it is show ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2025 09:24 PM
why are you concerned about file name in attachment type variable?
you can write onChange catalog client script on that Attachment type variable and use GlideAjax to validate it
💡 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 || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2025 10:11 PM
This is the working solution which worked for me fine
onChange catalog client script on Attachment type variable
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
g_form.hideFieldMsg('variableName');
var ga = new GlideAjax('ValidateAttachmentFileName');
ga.addParam('sysparm_name', 'checkFileName');
ga.addParam('sysparam_attSysId', newValue);
ga.getXMLAnswer(function(answer) {
if (answer.toString() == 'invalid') {
g_form.showFieldMsg('variableName', 'Invalid file name', 'error');
}
});
}
Script Include: It should be client callable
var ValidateAttachmentFileName = Class.create();
ValidateAttachmentFileName.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkFileName: function() {
var badChars = /[%$@()&<>'"]/;
var sysId = this.getParameter('sysparam_attSysId');
var gr = new GlideRecord("sys_attachment");
gr.addQuery("sys_id", sysId);
gr.query();
if (gr.next()) {
if (badChars.test(gr.file_name.toString()))
return 'invalid';
else
return 'valid';
}
},
type: 'ValidateAttachmentFileName'
});
Output: Working fine
💡 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 || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2025 02:27 AM
@Ankur Bawiskar
When I am uploading the attachment in the attachment type variable, I am getting the below error.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2025 02:29 AM
there is something wrong in your client script.
I already shared a working solution with you
share your scripts and screenshots of that script 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 || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader