How to Show Images in Info Messages in ServiceNow

I was recently working with a client who wanted to show an image whenever a specific addInfoMessage was displayed on the incident form. My first thought was that this was going to be a piece of cake since I knew that Info Messages (used in an “onDisplay” Business Rule in this case) could contain HTML.

So I began down my path. I first went to the “image picker” to find a suitable image; while there were a number of potential candidates, nothing really “popped”; so I decided I would add my own image/icon:

    1. First I went to Google’s image search and quickly snagged a great looking icon
    2. Opened the icon up in Gimp, and resized it to 20×20 (was 256×256 which was way too big for an info message)
    3. I then went to System UI -> Images -> New
    4. Specified a Category of “General”, and “Name”: IconName.png
    5. Then uploaded the image
    6. Now with the image in place we theoretically just needed to reference it in the infoMessage
          gs.addInfoMessage('<img src="IconName.pngx" /> This task message includes an icon')

And All Done… Right? Well, not so fast. Apparently, ServiceNow doesn’t display the image correctly when it is called in this manner. In order to workaround this behavior we have to perform some inline CSS styling (Nasty I know…) in order to display it “inline” with a width of 20px:

          gs.addInfoMessage('<img style="display: inline !important; width: 20px;" src="IconName.pngx" /> This task message includes an icon')

After adding in the styling the image was displayed properly and all again was right with the world.


Some Common Hurdles in Scoped Apps in ServiceNow

I was recently working with one of my mentors here at Crossfuze (big shout out to Jacob Anderson for his help!) to create a new scoped app: TFS Integration application. During this process I encountered a number of limitations I had to workaround in relation to scoped apps. Here is a quick summary of things that I found:

1. Script Includes: Never assume that you can reference an OOB “ServiceNow” Script Include, always check that it is “Accessible from:” is set to “All application scopes” (should not be “This application scope only”) before trying to use it (e.g. GlideEncrypter, ImportSetUtil, GlideHTTPRequest, XMLHelper, and GlideDBObjectManager, etc.)

  • Make sure when calling Script Includes outside of your app, that you use the API Name (contains scope prefix): e.g. new global.JSON()
  • A workaround to the “GlideEncrypter” is that you can now use the following code to retrieve the un-encrypted value: “gr.element_name.getDecryptedValue()”

2. Data Imports: When importing data you can’t use the ImportSetUtil so you must create a table that extends the Import Set Row (sys_import_set_row) table in order to load the data

3. Client Scripts: You should not use the DOM directly. Here’s a list of Client side APIs that have been turned off:

  • GlideRecord – can no longer use
  • window, document, $ (Prototype), $$ (Prototype selector), $j (jQuery), $F (Sizzle) – can only use them if you set the property below
  • All APIs above (except GlideRecord) can be re-enabled on a per-application basis. To do so, you need to set a True/False system property in your application named glide.script.block.client.globals with the value false

4. Server methods: Cant directly use methods such as “indexOf, toUpperCase, split…” functions, you must first convert the element “toString()” before using them (or use ArrayUtil if applicable).

5. Business Rules: You cannot use “Query” Business Rules

6. Client Scripts: You can only use the following g_form methods in the same scope as the calling script (don’t try using them on fields you didnt create in your app): “setReadOnly, setMandatory, setDisabled, setDisplay”

7. Long Running Transactions: Be aware of long-running queries (break your pulls/loads into “chunks”), if something in your apps runs longer than 10 minutes it will be killed based on the “Scoped Background Transactions” quota rule. Note that ServiceNow can override this on a per case basis.

8. Client Scripts: No longer can use “Global” Client Scripts within Client Scripts. Now must use UI Scripts for these (makes sense). Previously, if you wrote your own functions outside of the ServiceNow client script (e.g. outside the onChange/onLoad…), then that function was available to other client scripts as it was in the “global” context. That is no longer the case.

9. Forms: Can’t change forms or dictionary values of fields that are not in your scope
10. Fields: You cannot add new fields to the sys_user_group table


Have more issues you’ve found that I didn’t mention (very likely), please share them in the comments!

For more details please see the following links: