Image is everything
sys.properties
·
Oct 02, 2014
·
article
As you probably know, ServiceNow allows embedding images in HTML fields, and there are two ways of doing it: You can either add an image as an attachment, which makes it only available in the current record, or upload it to the Image Library, in which case it becomes reusable and can be later embedded in other pages or documents. You can find step-by-step instructions for both methods on the ServiceNow Wiki.
On the one hand, the possibility to upload an image once and then use it in multiple places across the system makes for increased consistency of the user interface and also saves you time. On the other hand, if you do not know where and how your images are used, deleting just one of them can spoil many things at once. If you intended to delete something, you would normally do it with extreme care and think twice before hitting the button. However, there is a scenario when you might delete an image from the library without even realizing what is going on.
You will be surprised but if you try to upload an image with a name that already exists in the library, the system will overwrite that image with your new one without any confirmation or hint. When I came across this issue some time ago, I started looking for a solution and now I am keen to share my findings with you.
The dialog window for embedding images in HTML fields is in fact a UI page called html_insert_image_dialog. When I looked at the client script part of that UI page, I saw a function named imageAlreadyExists() that was obviously supposed to check if an image with the same name was already present in the Image Library and if so, abort the upload. But why was it not doing that? It turned out that function’s behavior depended on the forceReplace parameter. Surprisingly, that parameter is true by default, so the function will always quit without performing any checks. If this is not how you want it to work, all you need to do is either set forceReplace to false inside the function itself or simply add the following line at the beginning of the client script:
GlideDialogWindow.get().setPreference('force_replace', 'false');
https://sys.properties/2014/10/03/image-is-everything/