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
3 weeks 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
3 weeks ago - last edited 3 weeks 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
3 weeks 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
2 weeks ago
Hi @Rafael Batistot
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
2 weeks ago
Hi @Shantharao ,
Can you check this article and adjust code as per your requirement: https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0723548#:~:text=Views%20Engli...
Have client callable script include:
var AttachmentSizeChecker = Class.create(); AttachmentSizeChecker.prototype = Object.extendsObject(AbstractAjaxProcessor, { checkAttachmentSize: function() { var maxSizeBytes = this.getParameter('sysparm_max_size_bytes'); var recordSysId = this.getParameter('sysparm_record_sys_id'); var grAttachment = new GlideRecord('sys_attachment'); grAttachment.addQuery('table_sys_id', recordSysId); grAttachment.query(); while (grAttachment.next()) { if (grAttachment.size_bytes > maxSizeBytes) { return 'true'; // Attachment size exceeded } } return 'false'; // No attachments exceeded the size limit }, type: 'AttachmentSizeChecker'});
And onSubmit Client script:
function onSubmit() { var recordSysId = g_form.getUniqueValue(); // Set your maximum file size in bytes (3 MB = 3 * 1024 * 1024) var maxSizeBytes = 3145728; var ga = new GlideAjax('AttachmentSizeChecker'); ga.addParam('sysparm_name', 'checkAttachmentSize'); ga.addParam('sysparm_record_sys_id', recordSysId); ga.addParam('sysparm_max_size_bytes', maxSizeBytes); ga.getXMLAnswer(function(response) { if (response == 'true') { // Display an error message in the portal alert('One or more attachments exceed the 3MB size limit.'); return false; } else { return true; } }); return false; }
If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !!
Thanks, GP