- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-16-2024 06:32 AM
How can I validate the type (xls/xlsm) and size (<5 MB) in an attachment variable and output an error for the same?
Can you write an onSubmit client script for the same?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-16-2024 07:31 AM
@Vignesh Raman - If you're using a variable of attachment type, use the following onChange script -
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ajax = new GlideAjax('Newglidingabc');
ajax.addParam('sysparm_name', 'checkAttachmentSize');
ajax.addParam('sysparm_existing', newValue);
ajax.getXML(getRITMdata);
function getRITMdata(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer) {
alert(answer);
g_form.clearValue("add_attachment"); //give your attachment variable name
}
}
}
Script include -
checkAttachmentSize: function() {
var grA = new GlideRecord("sys_attachment");
grA.addQuery("sys_id", this.getParameter("sysparm_existing"));
grA.query();
if (grA.next()) {
if (grA.getValue("size_bytes") > 5000) {
return "File size must be less than 5MB.";
} else if (grA.getValue("content_type") != "xls" && grA.getValue("content_type") != "xlsm") {
return "Please attach xls or xlsm files";
}
}
},
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-16-2024 06:52 AM
Hi @Vignesh Raman,
Did you created a separate variable called "Attachment" using attachment variable type or else using the OOTB attachment icon ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-16-2024 06:59 AM - edited ‎05-16-2024 06:59 AM
If you're trying to achieve the file type validation using the OOTB attachment option, please refer to the following video explanation on achieving this - https://www.youtube.com/watch?v=EUdkUfm0OGM
Best Regards,
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-16-2024 07:31 AM
@Vignesh Raman - If you're using a variable of attachment type, use the following onChange script -
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ajax = new GlideAjax('Newglidingabc');
ajax.addParam('sysparm_name', 'checkAttachmentSize');
ajax.addParam('sysparm_existing', newValue);
ajax.getXML(getRITMdata);
function getRITMdata(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer) {
alert(answer);
g_form.clearValue("add_attachment"); //give your attachment variable name
}
}
}
Script include -
checkAttachmentSize: function() {
var grA = new GlideRecord("sys_attachment");
grA.addQuery("sys_id", this.getParameter("sysparm_existing"));
grA.query();
if (grA.next()) {
if (grA.getValue("size_bytes") > 5000) {
return "File size must be less than 5MB.";
} else if (grA.getValue("content_type") != "xls" && grA.getValue("content_type") != "xlsm") {
return "Please attach xls or xlsm files";
}
}
},
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-24-2024 12:50 AM
Thanks for your response. Apologies for the delay in my response!