incident table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago
@I am creating an incident from the record producer with an attachment, and I want to fetch the attach attachment size, if it is greater than 3mb, I need to populate comments in the incident form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago - last edited a month ago
Hi @renukakandu - Depending on how and when the attachment is uploaded, you can do something like this:
// Get attachments linked to the producer (current)
var sa = new GlideRecord('sys_attachment');
sa.addQuery('table_sys_id', current.getUniqueValue());
sa.query();
while (sa.next()) {
var sizeMB = sa.size_bytes / (1024 * 1024);
if (sizeMB > 3) {
current.comments = "An attachment larger than 3 MB was uploaded (" +
Math.round(sizeMB * 100) / 100 + " MB).";
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago
Hi @renukakandu
Write a Business Rule on incident table and Condition Insert
var gr = new GlideRecord("sys_attachment");
gr.addQuery("table_sys_id", current.sys_id);
gr.addQuery("table_name", "incident");
gr.query();
var oversized = false;
while (gr.next()) {
var sizeInMB = parseInt(gr.size_bytes) / (1024 * 1024);
if (sizeInMB > 3) {
oversized = true;
break;
}
}
if (oversized) {
current.comments = "Note: One or more attachments exceed 3MB in size.";
current.update(); // Safe in after insert
}
Thanks,
Vignesh
"If this solution resolves your issue, kindly mark it as correct."
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago
you can use after insert BR on incident table and then query sys_attachment and know the size and accordingly update the comments
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.comments = '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
a month ago
I like this approach, especially the query-based check. I’m not sure if @renukakandu wants to enforce this for all incidents or only those created from the record producer. Technically, you should include a non-breaking space between the number and the unit, so like '\u00A0MB'.
