logo

NJP

Formatting within Journal fields using HTML & [code]

Import · Jan 13, 2017 · article

Most fields in ServiceNow store a single inputted text value. To view previous values one needs to go into the record's audit history. Journal fields are different, in that all previous values of this field are shown as distinct posts within the Activity Stream timeline. This allows them to be used as a method of communication with users and coworkers about the current record, and also as a log of the history of the record.

With journal fields, the content of notifications are commonly based on the newly updated value of the journal fields, and that they only accept input as plain-text. Out of box, there are two journal fields on the task table:

  • Additional comments [comments]
  • Work notes [work_notes]

Adding HTML code in Journal fields

As with most fields, if the new value contains HTML code it is escaped. For example, if you were to type the below valid HTML code in a journal field:

image

It would appear in the Activity Stream as follows:

image

The way this is done is by replacing any characters in a journal field that could be interpreted by a browser as HTML with it's HTML entity code.

For example, HTML tags make use of < and > to declare the start and end of a tag. ServiceNow replaces these with their HTML entity code < (less than) and > (greater than), meaning that when the browser reads the code it doesn't get processed as a literal < and >, and therefore does not mistakenly become a HTML element.

Using the [code] tag in Journal Fields

Text wrapped in [code] tags bypasses the escaping process described above, and will instead be rendered as HTML. For example, the same input used above, but wrapped in [code] tags:

image

Will appear in the Activity Stream as follows:

image

Note that the

tags are now being interpreted as HTML elements, and are not being escaped. Also note that you can use multiple sets of [code] tags within a single journal entry.

Formatting styles in Journal entries

There are a number of HTML elements that you can use to add styles to your journal updates. Some examples are shown below:

Style Tag(s) Example Journal Entry
Italic [code]This text is italic[/code]
image
Strikethrough [code]This text is strikethrough[/code]
image
Code (inline) [code]Check the script include KBKnowledgeBase[/code]
image
Code (block)
[code]
function foo() {
console.log('bar');
}
[/code]
image
Blockquote
[code]
This is a quote
[/code]
image
Hyperlink [code]
Bullet points
[code]
  • Item 1
  • Item 2
  • Item 3
[/code]
image
Numbered lists
[code]
  1. Item 1
  2. Item 2
  3. Item 3
[/code]
image
Header

[code]

This is a header

This is normal.[/code]
image

The HTML elements shown above do not contain any styling information - that is left up to ServiceNow's CSS stylesheets, and the browser's user agent stylesheet. Therefore, as the styles rely on ServiceNow CSS, the way they are presented to users may change after future user interface upgrades.

The above examples show how the HTML elements are displayed in the Istanbul release of ServiceNow, running UI16. See kobby.adu-nti demo in Formatting the Journal Field with the [code] tag

View original source

https://www.servicenow.com/community/in-other-news/formatting-within-journal-fields-using-html-amp-code/ba-p/2286203