- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2025 10:53 AM
Hi Team,
Can we restrict special characters (% $ @ ( ) & < > ' ") in the attachment type variable?
@Ankur Bawiskar
Solved! Go to Solution.
- 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! 🙏
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2025 11:01 AM
Are you talking about special characters in attachment name?
Can you elaborate more about your use case?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2025 12:34 AM
Hi @D V Sandeep ,
I check for your problem in my PDI and it works for me, I checked for name in file name please check solution below
I created a onChange client script on attachment variable and add below code
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
alert("Called = " + g_form.getValue('add_here'));
var attachmentWidget = g_form.getControl('add_here');
alert("attachmentWidget = " + JSON.stringify(attachmentWidget));
var fileName = attachmentWidget.displayValue
var invalidChars = /[%$@()&<>'"]/;
if (invalidChars.test(fileName)) {
alert("Your file name have invalid characters please remove and add");
g_form.clearValue("add_here");
return false;
}
}
Result
My file has special characters
Please mark my answer correct and helpful if this works for you
Thanks and Regard,
Sarthak
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2025 01:01 AM
Hi @SanjivMeher
When we try to attach a file to the attachment type variable in a record producer, the system should prevent the file from being attached if the file name contains special characters.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2025 01:16 AM
Hi @D V Sandeep ,
Did you check my solution ? I also did for file name only.