How to print comments through Email Notification script

gazalagrawa
Tera Contributor

Hi,

 

I am trying to print the last comment/worknotes in a notification using email script:

  template.print('Comments '+cs.comments.getJournalEntry(1));
                template.print('\n Work Notes '+cs.work_notes.getJournalEntry(1));
 
But it is displaying content as:
Comments Work Notes 2026-06-10 23:38 PDT - Gazal Agrawal (Work Notes) [code]

pls check this

[/code]
 
 
How can I remove this [/code]. What wrong I am doing here? These comments and worknotes are made through CSM Configurable workspace.
1 ACCEPTED SOLUTION

pr8172510
Tera Guru

Hi @gazalagrawa,

This behavior is commonly seen with CSM Configurable Workspace, where journal entries may be stored with formatting markers such as [code] and [/code].

Since getJournalEntry(1) returns the raw journal content, those tags are included in the output.

You can remove them before printing:

var comment = current.comments.getJournalEntry(1);
comment = comment.replace(/\[code\]|\[\/code\]/g, '');

template.print('Comments: ' + comment);

 

If you need only the actual comment text (without timestamps, usernames, or formatting), query the sys_journal_field table and use the value field instead of getJournalEntry().

View solution in original post

4 REPLIES 4

pr8172510
Tera Guru

Hi @gazalagrawa,

This behavior is commonly seen with CSM Configurable Workspace, where journal entries may be stored with formatting markers such as [code] and [/code].

Since getJournalEntry(1) returns the raw journal content, those tags are included in the output.

You can remove them before printing:

var comment = current.comments.getJournalEntry(1);
comment = comment.replace(/\[code\]|\[\/code\]/g, '');

template.print('Comments: ' + comment);

 

If you need only the actual comment text (without timestamps, usernames, or formatting), query the sys_journal_field table and use the value field instead of getJournalEntry().

Tanushree Maiti
Tera Patron

Hi @gazalagrawa 

 

Refer : KB0529930 Viewing last two comments when using getJournalEntry to add a journal entry to a notificat... 

 

With your code, you can  use regex to remove [/code] ,[code]tag.

 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti

Ankur Bawiskar
Tera Patron

@gazalagrawa 

you need to use email script to remove that text

use this

var comments = cs.comments.getJournalEntry(1);
var dateRE = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.*\n/;
var onlyCommentsText = comments.replace(dateRE, '');
template.print('Comments '+ onlyCommentsText );

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

OlaN
Tera Sage

Hi,

This is done because the CSM Workspace adds HTML formatting to a plain text field.
In order to display the HTML formatting correctly it needs to wrap the text in a [code] segment.
If you don't want to script this with an email script, you could just grab the text through the regular notification fields available.

One thing to note, is that this option grabs all the worknotes, not just the last one.

Otherwise the suggested workarounds of removing the "[code]" segment will work fine.

worknotes-on-notification.png