Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Smart Attachment Size Limiter
This Business Rule limits attachment sizes uploaded to ServiceNow records by enforcing a maximum size configured via the system property com.glide.attachment.max_size (in bytes). If the attachment exceeds the configured limit, the upload is blocked with an error message shown to the user. You can create or modify this system property to change the max size and update the property name in the script accordingly.

Scoped Application Note:
If deploying in a scoped application, configure Cross-Scope Access under System Applications > Application Cross-Scope Access to allow your app permission to access the sys_attachment table and related resources, avoiding security restrictions.

This approach keeps your instance performant by managing attachment size transparently without hardcoded limits.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
(function executeRule(current, previous /*null when async*/ ) {
if (current.table_name == 'incident') { //here multiple tables can be looped I am just using incident table
var maxSize = gs.getProperty('com.glide.attachment.max_size');
maxSize = parseInt(maxSize, 10);
if (current.size_bytes > maxSize) {
var maxSizeMB = (maxSize / (1024 * 1024)).toFixed(2);
var attachmentSizeMB = (current.size_bytes / (1024 * 1024)).toFixed(2);
// Prevent insert by setting error message
gs.addErrorMessage("Attachment '" + current.file_name + "' size (" + attachmentSizeMB + " MB) exceeds the max allowed size of " + maxSizeMB + " MB. Please reduce the file size.");
// Cancel the insert operation
current.setAbortAction(true);
}
}
})(current, previous);
Loading