email script notification

Bhavani1995
Tera Contributor

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
    /* Optional EmailOutbound */
    email, /* Optional GlideRecord */ email_action,
    /* Optional GlideRecord */
    event) {


    var number = current.number;
    var rejectNotes = "";
    var short_desc = current.short_description;
    var article_link = gs.getProperty('glide.servlet.uri') + "nav_to.do?uri=kb_knowledge.do?sys_id=" + current.sys_id;
    var author;
    var revisor = current.revised_by;
    if (revisor)
        author = revisor.first_name;
    else
        author = current.author.first_name;
    var lastComment, lastCommentLines;
    var approval = new GlideRecord("sysapproval_approver");
    approval.addQuery("document_id", current.sys_id);
    approval.addQuery("state", "rejected");
    approval.query();
    if (approval.next()) {
        lastComment = approval.comments.getJournalEntry(1);
        lastCommentLines = lastComment.split("\n");
        lastCommentLines.shift();
        rejectNotes = lastCommentLines.join('<br/>');
    }
    var emailContent = {};
    emailContent.templateContent =
        "Hi  " + author + ",<br/>" +
        "<br/>" +
        "<a href=" + article_link + ">" + number + "</a> is rejected.<br/>" +
        "<br/>" +
        "<b>Article Title</b>: " + short_desc + "<br/>" +
        "<br/>" +
        "<b>Rejection comments</b>: " + rejectNotes + "<br/>" +
        "<br/>" +
        "Please visit the article link if you want to revise the article.<br/>" +
        "<br/>";
    email.setSubject(number + " is rejected.");
    template.print(emailContent.templateContent);
})(current, template, email, email_action, event);
how to do changes in the email script so that sys_updated_by also receive the notification 
in the approval publish workflow in the create event param 1 is passed it is triggering to the author how to pass param 2 so that it should trigger to the sys_updated_by in the create event

6 REPLIES 6

KrishnaMohan
Giga Sage

Hi @Bhavani1995 

1) how to do changes in the email script so that sys_updated_by also receive the notification 
As per docs.   you can use below below methods. 

email

EmailOutbound object

Available methods:
  • addAddress(String type, String address, String displayname): type can be cc or bcc.
  • setFrom(String address): override the sender address.
  • setReplyTo(String address): override the reply to address.
  • setSubject(String subject): override the subject of the message.
  • setBody(String message): override the body of the message.
The email address that is passed by setFrom and setReplyTo needs to be in a valid form such as helpdesk@sn.com or Display Name <helpdesk@sn.com>. If the email address includes a 'Display Name', then that value overrides the instance's display name.

 

 

2) 

in the approval publish workflow in the create event param 1 is passed it is triggering to the author how to pass param 2 so that it should trigger to the sys_updated_by in the create event.

 


-you can pass param1 with comma separated user sys_ids (like author, updated ) 

KrishnaMohan_0-1757042951941.png
Event parm 1 contains recipientSelect this check box if the event parameter 1 contains one or more email recipients (in a comma separated list). This field is visible only when theSend when field is set to Event is fired.
Event parm 2 contains recipientSelect this check box if the event parameter 2 contains one or more email recipients (in a comma separated list). This field is visible only when theSend when field is set to Event is fired.

 

If this helped to answer your query, please mark it helpful & accept the solution.
Thanks!
Krishnamohan

 

 

Hi Krishna mohan

 

For sys_updated_by if we pass in the event param 1  will it trigger to the last updated user without doing any changes in the mail script 

Ankur Bawiskar
Tera Patron
Tera Patron

@Bhavani1995 

in the workflow itself where you are sending email ensure you pick the sys_updated_by, query sys_user and then include that as well in recipient list.

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Hi Ankur, can you share the changes of the script because I tried it is not working