- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Monday
Hi i want to display the message as soon as possible whenever an attachment is attached to the case and the combine size of attachments exceed 18mb then i want to show the error message immediately is this possible?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
9 hours ago
Small change in my Script & it worked fine for me
-> I added size bytes for the current file also, I forgot it earlier
(function executeRule(current, previous /*null when async*/ ) {
// Define your limit in bytes (e.g., 10MB)
var maxSize = 18 * 1024 * 1024; // 18 MB
var totalSize = 0;
var gr = new GlideRecord("sys_attachment");
gr.addQuery("table_sys_id", current.table_sys_id);
gr.query();
while (gr.next()) {
totalSize = totalSize + parseInt(gr.size_bytes);
}
totalSize = totalSize + parseInt(current.size_bytes);
if (totalSize > maxSize) {
gs.addErrorMessage('Total Attachment size exceeds the limit of 18 MB.'); // User-friendly message
current.setAbortAction(true); // Prevents the attachment from being saved
}
})(current, previous);
Output: I tried to add 3rd file and it exceeded 18MB and error message thrown and file not added
💡 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
Monday - last edited Monday
Hello @Raze00 ,
In ServiceNow:
Attachments are saved after upload
Client scripts cannot read attachment sizes directly
Total size exists only on the server
So the solution must be:
Client Script (detect upload) → Script Include (calculate size) → Client response
You have to go Like this .
User attaches file
↓
onSubmit / onChange (Client Script)
↓
GlideAjax call
↓
Script Include (sum attachment sizes)
↓
Return size
↓
Show error message immediately
it is possible, but only by calling a Script Include via GlideAjax from a Client Script to calculate the total attachment size server-side and return it immediately to the UI.
if you want script include just reply I will provide that as well.
If my solution is helpful , Accept it as solution 🙏or mark is as helpful as well👍.
Regards,
UmesH
Technical Consultant.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Monday
Hi, Yes if you can provide it. Thankyou.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Monday
did you try to use before insert BR on sys_attachment table and show some info message?
what did you try so far and where are you stuck?
💡 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
Tuesday
Hi ankur, i have created a br on hr core table as display br whenever the attachment is added and agent saves the form or reload it the error will show. what i want is that message to display immediately after the attachment is added because sometimes agent wont save the form after uploading an attachment .
