- 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
08-23-2023 08:28 AM
This was useful!
I know this is an old thread so I wanted to share an update with what we did differently. We used GlideAggregate to quickly get a sum of the record instead of a while.
Here is an example of a background script for a test against a specific record looking to see if there are more than 500MB worth of attachments on it. I used the limit variable just for testing.
var aggy = new GlideAggregate('sys_attachment');
aggy.addQuery('table_sys_id', 'b4d3414c938cbd14a45eb1874dba10fe');
aggy.addAggregate('SUM','size_bytes');
aggy.setGroup(false);
aggy.query();
var limit = 524288000;
if(aggy.next()){
gs.print(aggy.getAggregate('SUM', 'size_bytes'));
if(aggy.getAggregate('SUM', 'size_bytes') > limit){
gs.print("so big!");
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2023 08:24 AM
Was this as a client catalog script, script include, or a business rule?