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

Thanks Pradeep! The pop-up is coming with alert by using your suggestion. However, comments added to the incident and any other changes to the from are not being saved we click OK since we are aborting the action. The agent will have rework the ticket in this scenario. What can we do to save all the changes except resolving the ticket.



Regards,


Shalini


Shalini,



One thing you could try is rather than having the script run the current.setAbortAction(true); line is have the line do something like current.state == "whatever-not-resolved-is", and allow the submisson to complete otherwise. That way, the rest of the changes on the form can still be submitted, just the incident won't be moved to a "resolved" state.


So, my team likes the info message and not the pop up. The info message is working fine for me, but when I impersonate certain agents, the message comes up for   second and disappers and the ticket goes back to its original state. It does not save the updates to the ticket. Any idea why?


The code I am using is below with the condition: current.state.changesTo('6')



checkAttachmentSize();



function checkAttachmentSize() {

var totalsize = 0;
var attachment_size = new GlideRecord('sys_attachment');


//this queries for the attachments for the current record
attachment_size.addQuery('table_sys_id', current.sys_id);
attachment_size.query();
 
while (attachment_size.next()){
  totalsize = totalsize +   parseInt(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){  
  current.u_attachment_size_flag = true;
  current.setAbortAction(true); // stop the form submission+
  gs.addInfoMessage('The total size of attachments exceeds the maximum allowed limit of 18MB. Please remove attachments that are not needed and make sure the attachment size is < 18 MB and then try again.');
             
}
//else
//{   current.u_attachment_size_flag = false;
// current.update();
// }

}



Thanks,


Shalini


shalini44
Tera Expert

Thank you all for your suggestions!



I tried writing the business rule as suggested by Mike and it seems to work. I will discuss this solution with my team and see if they like this proposal.



Appreciate all your help!



Shalini