How can we control drag&drop functionality in file attachment?

rezadaneshvar
Kilo Explorer

I am changing some codes to limit the size and type of the attachment files and this can be done via "attachment" UI Page. This works where user try to attach files via attachment ui page, however when drag&drop is used they are able to attach whatever they want.

I have created an onAfter business rule to remove invalid files from sys_attachment table but when it removes the file the attachment link still appear on the form so how can I get rid of   incorrect links appear on the form as attachment links?

Also does anyone know what the best way is to check actual file type (not from extension) from server side code in ServiceNow?      

3 REPLIES 3

Mike Allen
Mega Sage

There are two attachment tables, sys_attachment and sys_attachment_doc.   Make sure you clean both.   Also, check the system properties.   Attachments can be controlled from there, as well (file size, extension, etc.).


srinivasthelu
Tera Guru

HI Reza,



You can achieve this system setting. Mike is correct. Here is the page that talks about properties his mentioning.



Administering Attachments - ServiceNow Wiki



Thanks


Srinivas


Hi Mike and Srinivas,


Thanks for your answers to my question, I think I should have explained more about the issue as I am aware of the related tables and also have already read the wiki page you mentioned.



System property glide.attachment.extensions just set the allowed extensions (white list) but service-now doesn't care about the real type of the files so if I change the extension manually I will be able to attach it. I have changed the code in 'attachment' UI page to check for real type of the file and it works so users are not able to attach prohibited files (in my case .exe .com .jar etc.) even if they change the extensions of the files manually.



The size property com.glide.attachment.max_size is just for a single file so I made changes to the code to check for size of all attachments too and limited the size of attachments for a specific ticket. All these scenario work when user uses 'attachment' UI page but when they add attachments via drag&drop functionality I cannot control them from client side (and actually I don't know   if I can) and this is the main part of my question that how we can control drag&drop functionality of ServiceNow?



Please note that I don't want to disable the Drag-and-Drop feature via system property glide.ui.attachment_drag_and_drop.



I have added a business rule to remove invalid files after insertion and it works to delete them but even though the file has been deleted by the business rule the attachment link still is shown on the form (which come from Drag&Drop code).



Update: It appears the UI macro "attachment_entry" just displays the attachment links in attachment page and not on top of the form as mentioned in its description. Still cannot find the source of code for drag&drop that cause the attachment links to be displayed on top of the form.



Thanks,


Reza