From a7b7262bc8a2241cfac0699c3432212b18f37537 Mon Sep 17 00:00:00 2001 From: Charanjeet <35090930+Charanjet@users.noreply.github.com> Date: Wed, 15 Oct 2025 00:36:56 +0530 Subject: [PATCH 1/5] Create Readme.md --- .../Business Rules/Smart Attachment Size Limiter/Readme.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 Server-Side Components/Business Rules/Smart Attachment Size Limiter/Readme.md diff --git a/Server-Side Components/Business Rules/Smart Attachment Size Limiter/Readme.md b/Server-Side Components/Business Rules/Smart Attachment Size Limiter/Readme.md new file mode 100644 index 0000000000..502c913352 --- /dev/null +++ b/Server-Side Components/Business Rules/Smart Attachment Size Limiter/Readme.md @@ -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. From fc57af84360c26cb8690147e8c39272f0940d09e Mon Sep 17 00:00:00 2001 From: Charanjeet <35090930+Charanjet@users.noreply.github.com> Date: Wed, 15 Oct 2025 00:39:50 +0530 Subject: [PATCH 2/5] Create Smart Attachment Size Limiter.js --- .../Smart Attachment Size Limiter.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Server-Side Components/Business Rules/Smart Attachment Size Limiter/Smart Attachment Size Limiter.js diff --git a/Server-Side Components/Business Rules/Smart Attachment Size Limiter/Smart Attachment Size Limiter.js b/Server-Side Components/Business Rules/Smart Attachment Size Limiter/Smart Attachment Size Limiter.js new file mode 100644 index 0000000000..644e7b7b22 --- /dev/null +++ b/Server-Side Components/Business Rules/Smart Attachment Size Limiter/Smart Attachment Size Limiter.js @@ -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); From 9149ae9683e71f189966245d42c2c88daef2b327 Mon Sep 17 00:00:00 2001 From: Charanjeet <35090930+Charanjet@users.noreply.github.com> Date: Wed, 15 Oct 2025 00:44:14 +0530 Subject: [PATCH 3/5] Delete Server-Side Components/Business Rules/Smart Attachment Size Limiter directory --- .../Smart Attachment Size Limiter/Readme.md | 7 ------- .../Smart Attachment Size Limiter.js | 14 -------------- 2 files changed, 21 deletions(-) delete mode 100644 Server-Side Components/Business Rules/Smart Attachment Size Limiter/Readme.md delete mode 100644 Server-Side Components/Business Rules/Smart Attachment Size Limiter/Smart Attachment Size Limiter.js diff --git a/Server-Side Components/Business Rules/Smart Attachment Size Limiter/Readme.md b/Server-Side Components/Business Rules/Smart Attachment Size Limiter/Readme.md deleted file mode 100644 index 502c913352..0000000000 --- a/Server-Side Components/Business Rules/Smart Attachment Size Limiter/Readme.md +++ /dev/null @@ -1,7 +0,0 @@ -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. diff --git a/Server-Side Components/Business Rules/Smart Attachment Size Limiter/Smart Attachment Size Limiter.js b/Server-Side Components/Business Rules/Smart Attachment Size Limiter/Smart Attachment Size Limiter.js deleted file mode 100644 index 644e7b7b22..0000000000 --- a/Server-Side Components/Business Rules/Smart Attachment Size Limiter/Smart Attachment Size Limiter.js +++ /dev/null @@ -1,14 +0,0 @@ -(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); From 7d8966658e17ec973bfdd981dcf0bac4bd0e139b Mon Sep 17 00:00:00 2001 From: Charanjeet <35090930+Charanjet@users.noreply.github.com> Date: Wed, 15 Oct 2025 00:45:46 +0530 Subject: [PATCH 4/5] Create Smart Attachment Size Limiter.js --- .../Smart Attachment Size Limiter.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Server-Side Components/Business Rules/Smart Attachment Size Limiter/Smart Attachment Size Limiter.js diff --git a/Server-Side Components/Business Rules/Smart Attachment Size Limiter/Smart Attachment Size Limiter.js b/Server-Side Components/Business Rules/Smart Attachment Size Limiter/Smart Attachment Size Limiter.js new file mode 100644 index 0000000000..644e7b7b22 --- /dev/null +++ b/Server-Side Components/Business Rules/Smart Attachment Size Limiter/Smart Attachment Size Limiter.js @@ -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); From 4e83ff259a1c4a1832a3076f5a4da8488cbba58d Mon Sep 17 00:00:00 2001 From: Charanjeet <35090930+Charanjet@users.noreply.github.com> Date: Wed, 15 Oct 2025 00:47:33 +0530 Subject: [PATCH 5/5] Create Readme.md --- .../Business Rules/Smart Attachment Size Limiter/Readme.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 Server-Side Components/Business Rules/Smart Attachment Size Limiter/Readme.md diff --git a/Server-Side Components/Business Rules/Smart Attachment Size Limiter/Readme.md b/Server-Side Components/Business Rules/Smart Attachment Size Limiter/Readme.md new file mode 100644 index 0000000000..502c913352 --- /dev/null +++ b/Server-Side Components/Business Rules/Smart Attachment Size Limiter/Readme.md @@ -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.