Attachment size pop up

shalini44
Tera Expert

Hi,

We have a requirement where we should prevent resolving a ticket if the total size of the files attached to the ticket is more than 18 MB and show a pop-up instead alerting the agent about the file size.The reason is that we attach all the attachments to the outgoing email whenever the ticket is resolved . ServiceNow does not send email notifications if attachments size is more than 18 MB. This has resulted in emails being blocked and landing in the 'Failed' Mailbox and the end user never gets informed that the ticket is resolved.

If you have any suggestion to solve this scenario, please share your input.

Thanks in advance for looking into this!

Best Regards,

Shalini

1 ACCEPTED SOLUTION

mike_donathan
Kilo Guru

Shalini,



You can query sys_attachment for the current record using a "Before" business rule to check the total size of the attachments before you resolve the incident.



Basically, you'd want the business rule to go something like this:



var totalsize = 0;


var attachment_size = new GlideRecord('sys_attachment');


attachment_size.addQuery('table_sys_id', current.sys_id); //this queries for the attachments for the current record


attachment_size.query();



while (attachment_size.next()){


        totalsize =+ attachment_size.size_bytes; //returns the total size of attachments in bytes.


}



var totalsize_MB = totalsize / 1000000; //converts the total size to MB



if(totalsize_MB > 18){


        gs.addErrorMessage('The total size of attachments exceeds the maximum allowed (in MB). Please remove attachments and try again.'); // error message


        current.setAbortAction(true); // stop the form submission


}




...or something along those lines. You'll probably need to tweak it a bit to get it to work in your instance (and to fix any bugs I have in there).


(Edit to highlight the code snippet as JavaScript for easier reading)


View solution in original post

14 REPLIES 14

srinivasthelu
Tera Guru

You need to set this property accordingly.(com.glide.attachment.max_size).



you can find more details here.Administering Attachments - ServiceNow Wiki



System will throw an alert if user wants to upload the larger file.


Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Shaiini,



You may find the below link helpful.


Administering Attachments - ServiceNow Wiki


Thanks for reply Pradeep! I will try this in my test environment and see how it works.


mike_donathan
Kilo Guru

Shalini,



You can query sys_attachment for the current record using a "Before" business rule to check the total size of the attachments before you resolve the incident.



Basically, you'd want the business rule to go something like this:



var totalsize = 0;


var attachment_size = new GlideRecord('sys_attachment');


attachment_size.addQuery('table_sys_id', current.sys_id); //this queries for the attachments for the current record


attachment_size.query();



while (attachment_size.next()){


        totalsize =+ attachment_size.size_bytes; //returns the total size of attachments in bytes.


}



var totalsize_MB = totalsize / 1000000; //converts the total size to MB



if(totalsize_MB > 18){


        gs.addErrorMessage('The total size of attachments exceeds the maximum allowed (in MB). Please remove attachments and try again.'); // error message


        current.setAbortAction(true); // stop the form submission


}




...or something along those lines. You'll probably need to tweak it a bit to get it to work in your instance (and to fix any bugs I have in there).


(Edit to highlight the code snippet as JavaScript for easier reading)