Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

notification mail scripts for additional comment

VanajaD
Tera Contributor

Unable to create mail script for additonal comments please help me,

this is the code that i'm trying 

 

 

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
          /* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
          /* Optional GlideRecord */ event) {
  // Get the additional comments
  var comments = current.comments;

  // Get the record number and short description
  var number = current.number;
  var short_description = current.short_description;

  // Build the email body
  var body = "There are additional comments on record " + number + ": " + short_description + "\n\n";
  body += comments;

  // Set email subject and recipient (replace with your details)
  var subject = "Additional Comments on Record " + number;
  var recipient = current.caller_id.email;

  // Send the email
  email.setSubject("New Comment added to Incident: " + incident.number);
  email.setBody("A new comment has been added to Incident " + incident.number + ": " + current.comments);
  email.addRecipient(current.caller_id.email);
  email.send();


})(current, previous);
1 REPLY 1

johnfeist
Mega Sage

Hi VanajaD,

The comments are not stored with the object.  They are in sys_journal_field.  To retrieve the most recent comment,  I set up a function in a script include so that I can use it wherever needed.  Here's the function:

getMostRecentComment: function(commentID) {
        var theComments = new GlideRecord("sys_journal_field");
        theComments.addEncodedQuery("element_id=" + commentID.toString() + "^element=comments");
        theComments.orderByDesc("sys_created_on");
        theComments.setLimit(1);
        theComments.query();
        if (theComments.next()) {
            return theComments.value;
        } else {
            return "---nuttin---";
        }
    },

You pass the sys_id of the object in question as the argument.  I always use something like "---nuttin---" so that I have a positive way of knowing that the function ran but didn't find anything.

Hope that helps.

:{)

Helpful and Correct tags are appreciated and help others to find information faster