Appending text to the Additional comments field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2022 01:54 PM
Hello community,
I am having trouble with a simple script to append text to the additional comments of an incident when the status is updated to Resolved. So far, I've created a before update Business Rule to take the analyst's string in the comments and add text to it before the comment is sent to the customer. The script partially works, but it adds the analyst's comment twice. See screenshot. Does anyone have any thoughts on what might be happening?
Code below:
(function executeRule(current, previous /*null when async*/) {
var comments = "\n" + "\n" + 'Your feedback is incredibly valuable to me! Please take a moment to fill out the survey above. My team and I thank you.' + '\n' + 'To take available past surveys, visit [code]<b><a href="https://nationwidechildrens.service-now.com/iss?id=nch_my_surveys">My Surveys</a></b>.[/code]';
current.comments += comments;
})(current, previous);
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2022 02:07 PM
Hi,
The problem with comments and work notes is that they are journal entries and they are controlled on the record as well. So if the fulfiller used the "post" button, then comments have already gone to the user.
If you're requiring comments as part of the update to resolved process, then yes, the comments would be supplied and there as part of the record save. Is that how you have things setup?
I don't think you'll be able to correct this behavior in a business rule due to the journal entry, unless this is somehow caused by current.update() or something being in another business rule for this table, but due to the fact that we see it in the screenshot all part of 1 comment, I don't think that's what is happening.
The duplicate nature is because the comment has already posted and then you're still concatenating it, but then posting the comment again.
So 2 ways here:
1) You can change your script to:
current.comments = comments;
And so their comment would be above, and your survey request text would show after (this would also confirm that the journal entry they made (their comments) punch through before the BR can even intercept it anyway...since you're trying to say the current.comments should ONLY = this, but you'll most likely see that it doesn't do that and it's treated as a line break instead.
or...
2) Adjust all this in the notification itself to where you post your text and then show the comment after (then maybe consider not sending the "comments have been made" notification (if that exists) when the state changes to resolved.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!