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
2 hours ago
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
an hour ago - last edited an hour ago
Hi @Shantharao ,
Can you try with insert Business rule in Attachment table
Condition : Table name is incident
Sample Script:
// Set the attachment size limit to 3 MB in bytes var ATTACHMENT_SIZE_LIMIT = 3 * 1024 * 1024; // Check if the current attachment's size is greater than the limit if (current.size_bytes > ATTACHMENT_SIZE_LIMIT) { // Use GlideRecord to find and update the parent incident record var incidentGr = new GlideRecord('incident'); if (incidentGr.get(current.table_sys_id)) { incidentGr.comments = 'One or more attachments on this incident are larger than 3 MB. Please review them as necessary.'; incidentGr.update(); } }
If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !!
Thanks, GP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
Hi @Shantharao
If you am want to set a limit for all intance:
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0718101
if you want some specific for you case in incident, may you need create some customized
See an example:
You don’t need apply the logic in record producer directly
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
59m ago
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