- 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,936 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 10:14 AM
I was able to merge my two scripts and keep it working.
Thanks! This will definitely be a workaround for us - and our notifications are ok too which is good.
I had already entered a Hi ticket as well and contacted our Sales rep to see if he can get any traction moving on this issue.
But I really appreciate the workarounds you guys figured out!
Thanks!
Lori
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2015 10:46 AM
Our notifications are also working, I did not notice any issue with that. So, I didn't need to try the separate fields for notifications as I had previously thought I might.
Josh what were the issues with your notifications? Both of us are OK with our notifications.
Anyhow we certainly owe thanks to Josh for this workaround.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-03-2020 09:29 AM
Hello,
I see this post is from 5 years ago. We just migrated to SN and our management wants the same functionality where the work notes and additional comments field should accept html formatted text as input. Just checking to see if the solutions provided above worked for everyone in this thread or are there still issues with this? We are using Madrid so has anything changed in this version regarding this issue?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-23-2020 12:51 AM
Same situation here.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-08-2020 10:31 PM
The cleaner way to do it is to add a new custom field that would replace the existing work notes field and to use that field to fill the notes.
- Create new field of type HTML (u_work_notes) on task table
- On form layout replace the work notes field by that new field
- Create the following business rule
Name: Populate work notes from HTML
Table: Task
Advanced: True
When: before
Order: 100
Insert: true
Update: true
Filter conditions: Notes changes
Script:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
current.work_notes = ("[code]" + current.u_work_notes + "[/code]" );
current.u_work_notes = "";
})(current, previous);
But you will not see the post button after that