Skip to content

Commit 7d89666

Browse files
authored
Create Smart Attachment Size Limiter.js
1 parent 9149ae9 commit 7d89666

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
(function executeRule(current, previous /*null when async*/ ) {
2+
if (current.table_name == 'incident') { //here multiple tables can be looped I am just using incident table
3+
var maxSize = gs.getProperty('com.glide.attachment.max_size');
4+
maxSize = parseInt(maxSize, 10);
5+
if (current.size_bytes > maxSize) {
6+
var maxSizeMB = (maxSize / (1024 * 1024)).toFixed(2);
7+
var attachmentSizeMB = (current.size_bytes / (1024 * 1024)).toFixed(2);
8+
// Prevent insert by setting error message
9+
gs.addErrorMessage("Attachment '" + current.file_name + "' size (" + attachmentSizeMB + " MB) exceeds the max allowed size of " + maxSizeMB + " MB. Please reduce the file size.");
10+
// Cancel the insert operation
11+
current.setAbortAction(true);
12+
}
13+
}
14+
})(current, previous);

0 commit comments

Comments
 (0)