Code tags ([code]<p>) are added when additional comments are added to Incident from Service Portal

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2023 01:15 AM
Code tags ([code]<p>, </p>[/code]) are added when additional comments are added to the Incident from Service Portal.
We have Incident Management integrated with JIRA software, and the comments are added with code tags in the JIRA tool but look fine in ServiceNow (Service Portal and Native UI). We had the same issue with the email notifications sent for the JIRA-integrated tickets, it got solved by adding a before-insert business rule. But the same solution is not working for additional comments.
(function executeRule(current, previous /*null when async*/) { current.comments = current.comments.replace("[code]<p>", "").replace("</p>[/code]", ""); })(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2023 04:33 AM
Hi @Community Alums ,
The code provided seems to attempt to remove the code tags (specifically <p> and </p>) from the current.comments field in a before-insert business rule. However, it appears that the replacement logic is incorrect, as it uses square brackets ([]) instead of angle brackets (<>) for the code tags.
To correctly remove the code tags from the current.comments field, you can modify the code as follows:
(function executeRule(current, previous /*null when async*/) {
current.comments = current.comments.replace("<p>", "").replace("</p>", "");
})(current, previous);
This updated code should correctly replace the opening <p> and closing </p> tags with an empty string, effectively removing them from the current.comments field.
Shravan
Please mark this as helpful and correct answer, if this helps you

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2023 04:59 AM
Hi @Sai Shravan Thanks for your reply.
I tried and it didn't work.
Actually, my original code partially works if I make it a before-update business rule. It inserts the comments twice, one with code tags and one without code tags.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2023 04:26 AM
@Ankur Bawiskar Hi Ankur, Thanks for your help with my previous question.
Would you be able to help on this one?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2023 12:46 AM
Hi RJ8
To resolve the issue of code tags ([code]<p>, </p>[/code]) being added when additional comments are inserted into the Incident from Service Portal, you can try the following code snippet:
(function executeRule(current, previous /*null when async*/) { current.comments = current.comments.replace(/\[code\]<p>/g, "").replace("</p>\[\/code\]", ""); })(current, previous);
It could be an option to consider a 3th party tool to do this more seamlessly like Exalate, which is a platform that facilitates synchronization and collaboration between different issue trackers. I have been using it quite a while and it works amazing!