Creating an incident from a record producer with an attachment, if attachment size is more than 3MB
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-30-2025 01:20 AM
Creating an incident from a record producer with an attachment, if attachment size is greater than 3 mb, need to populate the comments in the same incident script logic in servicenow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-30-2025 02:08 AM
you can use after insert BR on incident table and then query sys_attachment and know the size and accordingly update the work notes
Business Rule: After Insert on incident
Script:
(function executeRule(current, previous /*null when async*/) {
var grAttachment = new GlideRecord('sys_attachment');
grAttachment.addQuery('table_name', 'incident');
grAttachment.addQuery('table_sys_id', current.sys_id);
grAttachment.addQuery('size_bytes', '>', 3145728); // 3 MB in bytes
grAttachment.query();
var largeAttFiles = [];
while (grAttachment.next()) {
largeAttFiles.push(grAttachment.file_name + ' ('+(grAttachment.size_bytes/1048576).toFixed(2)+' MB)');
}
if (largeAttFiles.length > 0) {
current.work_notes = 'The following attachments uploaded are larger than 3MB:\n' + largeAttFiles.join('\n');
current.setWorkflow(false);
current.update();
}
})(current, previous);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-02-2025 06:07 AM
Hope you are doing good.
Did my reply answer your question?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-05-2025 11:47 PM
Hi @Ankur Bawiskar ,
it is not working and client wanted the error message in the Portal,
When we added greater than 3mb attachment, need to show error message in the portal and stop the form submission
Thanks in advance for you response, have a nice day
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-06-2025 12:00 AM
then you can try to use DOM manipulation and extract the file size and throw error
I don't think you can validate the file size during catalog item submission.
1) search anchor tag with this class "get-attachment ng-binding ng-scope"
2) iterate and extract the file name which includes the size
3) do string manipulation and grab the size in either KB, Bytes or MB
4) then add and validate
Example: I added 3 files so it will have 3 anchor tag with that class, you can extract the text within that anchor tag and do the next steps
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-07-2025 02:29 AM - edited ‎10-07-2025 02:32 AM
Hi @Ankur Bawiskar
Thank you for the response the attached screenshots are not clear, could you please provide the OnSubmit client script through validate the functionality.
Thanks in advance for your support and have a nice day
