- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
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
a week ago
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 || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a week ago
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 || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a week ago - last edited a week ago
@Ankur Bawiskar
I used the same solution which you shared here, please check the below screenshot.
FYI, I also used 'allowed_extensions=csv' variable attribute for this variable.
Client Script (Customer Service Application Scope)
Script Include:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a week ago
any reason you created script include in global scope even though catalog item is in CSM scope?
client script is in which scope?
Both client script + script include should be in same scope as that of Record Producer i.e. Customer Service
Once you do that it will work fine. for my example my catalog item was in global scope hence I created Script include in global scope
💡 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
a week ago - last edited a week ago
At first I tried with the same scope (customer service) for both scripts, it gave me the same error so I just created a script include in global to check but unfortunately I got the same error.
I am getting the below two errors when I created script include in customer service:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a week ago
@Ankur Bawiskar
The issue was with the AbstractAjaxProcessor base class in the Script Include, and I resolved it by referencing global.AbstractAjaxProcessor.
Thank you for your help.