- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2015 12:44 AM
I am running into an issue where I can't seem to get the formatted comments to output when I use it a mail script.
Example:
I have a "comment added" type notification set up to go out whenever a comment is added and send to the caller. Our comments are done using HTML code, so to preserver that, I can just put the following in the mail body:
${comments}
And it will put out the last few most recent comments with all the formatting from service-now preserved. My problem comes when I try to edit any of this output. As far as I'm aware this needs to be done through a mail script. So let's say I create a mail script, and now instead of ${comments} I have the script name ${mail_script:HTML_Comment_Script} (and of course have to create a script of this name in the mail scripts section).
var suggComm = current.comments;
template.print("\n" + suggComm);
Shouldn't this be the same as ${comments}? What is different about the mail scripts in how I can access the same field information? Currently what happens is just nothing comes back.
My end goal is I have to figure out a way to do two things:
a.) Modify the img src tags to decode the %20 back to space characters because when it goes out in an email, if any file has a space in the name the encoded %20 is treated as literal set of characters and the image won't show in the received email.
b.) Only grab the latest comment. I know there is a global parameter to change how many get sent out, but changing that is not an option for me due to other workflows. If anyone knows how to change this on a per-call basis I'd love to know how, seems like it would be a handy feature to just pass some sort of a parameter in that changes how many "deep" the comments go and disregards the global parameter. However, either way I should be able to handle it with some regex scripting if i can just get the comment to actually output, which currently I can't do so I'm sort of dead in the water.
Best regards,
Brian Cronrath
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2015 02:51 PM
Hello ntylenda,
I did come up with a solution, I'm not sure if it is the greatest but it was the best I could come up with. I am basically stripping back out the [code] tags, and manually adding in the border format to mimic what Service Now does with the comment output. Here is my mail script:
var suggComm = current.comments.getJournalEntry(1);
suggComm = suggComm.replace("[code]","");
suggComm = suggComm.replace("[/code]","");
suggComm = "<div><table cellpadding=\"0\" cellspacing=\"0\" style=\"table-layout:fixed\" width=\"100%\"><tbody><tr><td colspan=\"2\"><hr /></td></tr><tr style=\"\"><td class=\"tdwrap\"><strong>" + suggComm;
suggComm = suggComm.replace("(Journaled comments)","</strong>");
suggComm = suggComm + "</span></span></p></td></tr></tbody></table></div>";
template.print("\n" + suggComm);
Hope this helps!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2015 12:49 AM
You can replicate the ${comments} by the following code:
template.print("${comments}")
This will essentially be the same as ${comments} in the email template.
It still gets parsed after it is printed to the template.
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2015 12:54 AM
Thank you Paul, I will give this a try here real quick
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2015 01:05 AM
Hmm so while it does work, I'm still unsure of how I can edit the output of the comments via script? Even something simple right now as performing a replace on the comments string just to verify I can get something to actually modify the output of the comment while still preserving the formatting.
For instance, I can use current.comments.getJournalEntry(1) to get the most recent external comment (in plain text though, not formatted) and perform any number of modifications to that string and then output it back. Unfortunately doing this removes the nice formatting I get when I just pull the {comments} w/ JQuery. I'm wondering if there is a way to edit the output in such a way?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2015 01:15 AM
If you want to edit the raw comments, you are going to have to write your own custom script as there is no way to put ${comments} into a variable and parse that.
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022