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

Bhimashankar H
Mega Sage

Hi @Bhavani1995 ,

 

In email notification 'Who will receive" tab select the 'sys_updated_by' field in user/Group field to receive the notification.

 

You can do it by adding below code snippet in script

email.addAddress("cc", current.sys_updated_by,"")

 

For more information refer below

Notification Email Script 

 

Thanks,
Bhimashankar H

 

-------------------------------------------------------------------------------------------------
If my response points you in the right directions, please consider marking it as 'Helpful' & 'Correct'. Thanks!

Hi Bhimashankar, 

How should I add in the email script so that when approver rejects the knowledge article then sys_updated_by should receive the reject notification

(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);