Tutorial: embed attached images in the activity history of any ticket. (Fuji)

arodenas
ServiceNow Employee
ServiceNow Employee

The Activity Formatter as of today is primarily geared for a text-only discussion, but it is possible to embed small snippets of HTML inside of the activity detail of any given ticket. This can be done by surrounding each HTML snippet with encapsulating "[code]" "[/code]" tags. Utilizing that feature, 2 additional Business Rules, and a Dictionary modification we will end up with a result that looks like the following:

Screen Shot 2015-07-08 at 1.58.02 PM.JPG

Step 1

Right-click on the "Work notes" label and select "Configure Dictionary.

Screen Shot 2015-07-08 at 2.11.54 PM.JPG

Change the "Type" from Journal to HTML and save your changes.

Screen Shot 2015-07-08 at 2.13.34 PM.JPG

Step 2

Create the two business rules as shown below. Make sure to activate them.

Business Rule: "Clear out work_notes field onDisplay"

- TABLE: task

- WHEN: display

- SCRIPT:

function onDisplay(current, g_scratchpad) {

    // Clears out work_notes field to emulate journal-like behavior with HTML field.

    current.work_notes = "";

}

Business Rule "Wrap work_notes with code tag"

- TABLE: task

- WHEN: before insert or update

- SCRIPT:

function onBefore(current, previous) {

    // If no opening [code] tag found, wrap it.

    var note = current.work_notes + "";

    if (note.indexOf("[code]") == -1) {

          var wrappedNote = "[code]" + note + "[/code]";

          note = wrappedNote;

    }

    current.work_notes = note;

    // Workaround to inject style attribute into image tags.

    var note = current.work_notes + "";

    var noteStyle = note.replace("\<img style\=\"", "\<img style\=\"display\: block\; ");

    if (note != noteStyle) {

          current.work_notes = noteStyle;

    }

}

Feel free to comment here if you have any questions or have found even better ways of accomplishing this! As always, please thoroughly test these customizations in each of your sub-production environments prior to implementation in your production environment.

2 REPLIES 2

arodenas
ServiceNow Employee
ServiceNow Employee

Here's another example that includes both a list, table, and image in one work_note update.


Screen Shot 2015-07-08 at 3.26.27 PM.JPG


arodenas
ServiceNow Employee
ServiceNow Employee

Changing the type of the work_notes field from Journal to HTML will cause a change in what the "Comments and Work notes" field displays in a list. Namely, no work_notes will display in this column on a list after changing work_notes to a HTML field.