- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-13-2017 07:27 AM
I'm trying to build a business rule in order to reject small attachments (Our company has a few ones like the linkedin logo, twitter and the company one) which get attached on every incident. Is there a way I can set a business rule on the sys_attachment table which does this? I tried as you can see in the image below, but unfortunately it will not allow me to choose 'Less than' for 'Size bytes'. Does anyone know how I can set it to do this?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-13-2017 07:38 AM
Hi Morgan,
you will have to write script for that. before insert business rule with following script.
var grInc = new GlideRecord('sys_attachment);
grInc.addQuery('table_name',"<tableName>"); // give table name as per your requirement
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>) { // give size in bytes as per your requirement
gs.addInfoMessage("Attachment size should be at least <your Size Limit>");
current.setAbortAction(true);
}
Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-13-2017 07:38 AM
Hi Morgan,
you will have to write script for that. before insert business rule with following script.
var grInc = new GlideRecord('sys_attachment);
grInc.addQuery('table_name',"<tableName>"); // give table name as per your requirement
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>) { // give size in bytes as per your requirement
gs.addInfoMessage("Attachment size should be at least <your Size Limit>");
current.setAbortAction(true);
}
Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-13-2017 08:12 AM
Hi Ankur,
Thank you for your email, that is very helpful. I've just got one question:
Which table are you referring to here? Would this be the incident table in my example to prevent people inserting attachments for that table?
grInc.addQuery('table_name',"<tableName>"); // give table name as per your requirement
grInc.addQuery('table_sys_id',current.sys_id);
Thank you very much again.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-13-2017 08:34 AM
Hi Morgan,
Consider user is attaching some attachment on incident record then in that case tableName would be incident.
If you have some other table then that name will come at that place.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-13-2017 07:45 AM
Hi Michael,
You can make it run on update with below script which checks for size & aborts if it is less than 5 kb
if(current.size_bytes < 5'){
current.setAbortAction(true);
}