I need to check the file attachment size on the form on submit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2022 12:11 AM
Need to write a Client Script where the attachment file should not be bigger than 5 MB , after uploading the file , when click on Submit it should throw an alert message and user should not be able to submit the request before uploading the right size file.
- Labels:
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2022 12:25 AM
Hello,
Check this thread, It has code
https://community.servicenow.com/community?id=community_question&sys_id=c71a43661bdd30507a5933f2cd4bcb40
Please hit like and mark my response as correct if that helps
Regards
Regards,
Musab
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2022 12:39 AM
Hi
I have tried the below code but it is not working
function onSubmit() {
//Type appropriate comment here, and begin script below
var sys_id = g_form.getUniqueValue();
var gr = new GlideRecord('sys_attachment');
//gr.addQuery("table_sys_id", cat_id);
gr.addQuery('table_sys_id',sys_id );
gr.Query();
var totalSize=0;
while(gr.next()) {
totalSize = parseInt(gr.size_bytes);
totalSize=(totalSize / Math.pow(1024, 2)).toFixed(2) * 1;
if(totalSize > 5) {
alert("Attachment size exceeded");
return false;
}
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2022 04:15 AM
Hello,
If you are fine with my response, Please hit like and mark my response as correct if that helps.
Regards
Regards,
Musab
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2024 06:33 AM
Hi, Add the below variable attribute for the attachment variable:
max_file_size=5
here 5 denotes 5 MB, you can change number as per your requirement.
Thanks,
Pritam