- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-17-2015 10:00 AM
Our management and user base wants to be able to insert inline images into Additional Comments and work notes and have them display correctly in the journal (Activity log). This is something that our previous system did well and which is missing in ServiceNow.
I am looking for a way to do this as seamlessly as possible. I have followed this guide: Implementing HTML in Comments - ServiceNow Wiki, with both Work Notes and additional comments, however I am having some issues.
1. Things entered in the new fields are correctly transferring to the OOB comments and work_notes fields and displaying html formatting with the exception of images. which are not displayed at all.
2. When attaching a suggested KB it ends up in description instead of the correct field (comments or u_comments) as the expected comments field is no longer on the form. I have looked but cannot find the logic that controls where to insert the attached KB text.
Any suggestions on how to solve the above or to better accomplish our goals?
Thanks,
-Josh
Solved! Go to Solution.
- Labels:
-
User Interface (UI)
- 20,932 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-16-2015 08:24 AM
The below was provided mostly by ServiceNow support:
Steps to Resolution:
1) Set the field in question (or create a custom field) to Type: HTML
2) In the dictionary for the field, create an attribute for HTML Sanitize and set the value to false.
3) Create a business rule that auto inserts code tags and sets the Style to display: block
4) [OPTIONAL] I created another onDisplay business rule that wiped out the field so the content of the field did not linger.
Additional details
2. add html_sanatize=false to the attributes of the new html field.
3. add on before business rule to field
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;
}
// Clunky workaround to inject style attribute into image tags.
var noteStyle = note.replace(/\<img style\=\"/g, "\<img style\=\"display\: block\; ");
if (note != noteStyle) {
current.work_notes = noteStyle;
}
}
4. you will find that HTML fields do not clear field contents after submit so you can create an onDisplay script to clear the filed:
current.field_name = '';
NOTE: At this time this will prevent the Additional Comments block form generating correctly in notifications
Edit: fixed .replace as per Leslie's suggestion.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2015 08:11 AM
Hi Lori, Did you follow all of the instructions step by step according to Josh's description?
Try to make sure you have the HTML escape attribute set to False.
html_sanatize=false
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2015 08:37 AM
Hi, Leslie -
Yes, I did add the attribute - though I think it is spelled wrong in the post - I added html_sanitize=false (with an 'i').
Our html field is also called Work Notes, but it is a custom work notes field (u_work_notes). So that is the only change I made to the code...
Here are screenshots of the dictionary entry and the business rule:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2015 08:40 AM
Leslie,
I have not tested the new .replace() that you provided and I updated in the answer. Can you confirm that the .replace() I have listed is the one that works for you ?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-26-2021 07:45 AM
Hello
Thank you so much for this solution and share with us.
This is very helpful and good solution.
Hi
Where is this code should be? is this refer to form client script - onload type?
if the new html field is working already, i can just remove the additional comment field from the form? can i remain this text only additional comment as, using this we can post comment can use "@" to mention someone, these features already using by users.
and the business rule is the form business rule?
*Edit; to add after test comment, i tried to implement this , but if i included text and image at the same time, after saving, only the image is add to the activity, text is not included.
Hope to hear for you.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-10-2022 11:13 PM
Hello @josh.tessaro
Thank you for this article.
I have the same requirement to add this.
Add the business rule as shared, i add a new field (HTML),
but if i adding an image with text, only the image will be display in the activities field.
i have no idea what happens,
After i save the document activities only show picture without text.
if i add text only in the HTML comment after save, nothing add to the activities.
Any one have idea what happened.
is there anything need to change in this business rule?
the "u_work_notes" is the html comment field ?
Appreciate if any help. Thank you.