- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2017 05:31 AM
Hi,
I have attachment limit size 20 MB.I have given this size limit in "System Properties>Security". But i can attach many files with 15 MB ,15 Mb..etc. How can i restrict total size of all attachments. For examble, if I am attaching 5 files for one Incident, total size of all those 5 files should not exceed 20 MB,How can calculate already attached files when attaching new file for though error?
!Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2017 06:07 AM
Hi Venkatesh,
i am not aware of a system property that would do that for you. You can however, write a script to restrict total size. You can create a business rule before insert in sys_attachment table that checks the cumulative size of all attachments for a particular record. So lets say you are limiting size on the incident table. Something like:
var grInc = new GlideRecord('sys_attachment);
grInc.addQuery('table_name',"incident");
grInc.addQuery('table_sys_id',current.sys_id);
grInc.Query();
var totalSize=0;
while(grInc.next()) {
totalSize+= parseInt(grInc.size_bytes);
}
if(totalSize+parseInt(current.size_bytes) > <your Size Limit>) {
gs.addInfoMessage("Attachment size exceeded");
current.setAbortAction(true);
}
Manish
PS: Mark as Helpful or Correct if this helps or solves your problem
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2017 06:04 AM
HI Venkatesh,
Maximum file attachment size in MegaBytes(MB) property. Leave the field empty to allow attachments up to a maximum of 1GB. By default, this field is blank.
Thanks,
Rajashekhar Mushke
Rising star : 2022 - 2024
Community Leader -2018
Connect me on LinkedIn : Rajashekhar Mushke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2017 06:07 AM
Hi Venkatesh,
i am not aware of a system property that would do that for you. You can however, write a script to restrict total size. You can create a business rule before insert in sys_attachment table that checks the cumulative size of all attachments for a particular record. So lets say you are limiting size on the incident table. Something like:
var grInc = new GlideRecord('sys_attachment);
grInc.addQuery('table_name',"incident");
grInc.addQuery('table_sys_id',current.sys_id);
grInc.Query();
var totalSize=0;
while(grInc.next()) {
totalSize+= parseInt(grInc.size_bytes);
}
if(totalSize+parseInt(current.size_bytes) > <your Size Limit>) {
gs.addInfoMessage("Attachment size exceeded");
current.setAbortAction(true);
}
Manish
PS: Mark as Helpful or Correct if this helps or solves your problem

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2017 06:13 AM
For performance reasons I recommend using GlideAggregate when you simply want to count, sum, max, min, or avg a number of records. GlideRecord is useful if you are doing something other than one of those operations. The reason is because GlideRecord actually has to retrieve those records and it could slow down performance where as GlideAggregate uses database functions to perform them much faster.
Also, there's a minor typo in your script "grInc.Query()" should be grInc.query();
You might also want to consider using getValue(), especially when inside a while loop to avoid a common pointer issue. Using built-in getters and setters is a best practice in programming.
var grInc = new GlideRecord('sys_attachment);
grInc.addQuery('table_name',"incident");
grInc.addQuery('table_sys_id',current.table_sys_id);
grInc.query();
var totalSize=0;
while(grInc.next()) {
totalSize+= parseInt(grInc.getValue('size_bytes'));
}
if(totalSize+parseInt(current.getValue('size_bytes')) > <your Size Limit>) {
gs.addInfoMessage("Attachment size exceeded");
current.setAbortAction(true);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2017 06:26 AM
Another minor correction !
grInc.addQuery('table_sys_id',current.table_sys_id); //actual record sys ID

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2017 01:42 PM
Thanks. Corrected.