Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

How to print author name in notification email content on sysapproval table

SomashekarB6490
Tera Contributor
Here is code, currently it's not printing   
 
 
var number = current.number;
    var rejectNotes = "";
    var short_desc = current.short_description;
    var article_body = current.text;
   
    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 approval = new GlideRecord("sysapproval_approver");
approval.addQuery("document_id", current.sys_id);
approval.addQuery("state", "rejected");
approval.query();
if (approval.next()) {
    var approvalSysId = approval.sys_id;
}
    var approval_link = gs.getProperty('glide.servlet.uri') + "nav_to.do?uri=sysapproval_approver.do?sys_id=" + approvalSysId;

    var emailContent = {};
    emailContent.templateContent =
        "<div style='font-size:10pt; font-family:verdana;'>" +
        "Dear  "+author+",<br/>" +
        "<br/>" +
        "Knowledge Article: " + number + " has been rejected for publication. Please review the Approver's comments, adjust the article and re-send it for approval.<br/>" +
        "<br/>" +
        "Click here to review the rejected request: <a href='" + approval_link + "'>rejected request</a><br/><br/>" +
        "Short description: " + short_desc + "<br/>" +
        "<br/>" +
        "Article body: " + article_body + "<br/><br/>" +
        "Click here to view the article: <a href='" + article_link + "'>View Article</a><br/><br/>" +
        "<br/>" +
        "Thank you."
1 ACCEPTED SOLUTION

sunil maddheshi
Tera Guru

@SomashekarB6490 

current.author might be a reference field, and you're trying to access first_name directly without ensuring it's a valid GlideRecord object.

 

var number = current.number;
var rejectNotes = "";
var short_desc = current.short_description;
var article_body = current.text;

var article_link = gs.getProperty('glide.servlet.uri') + "nav_to.do?uri=kb_knowledge.do?sys_id=" + current.sys_id;

// Initialize author variable
var author = "Unknown Author"; 

// Retrieve the revisor (if available)
var revisor = current.revised_by;
if (revisor) {
    var userRecord = new GlideRecord("sys_user");
    if (userRecord.get(revisor)) {
        author = userRecord.first_name;
    }
} else if (current.author) {
    var userRecord = new GlideRecord("sys_user");
    if (userRecord.get(current.author)) {
        author = userRecord.first_name;
    }
}

// Retrieve approval link
var approval = new GlideRecord("sysapproval_approver");
approval.addQuery("document_id", current.sys_id);
approval.addQuery("state", "rejected");
approval.query();

var approval_link = "#"; // Default value
if (approval.next()) {
    approval_link = gs.getProperty('glide.servlet.uri') + "nav_to.do?uri=sysapproval_approver.do?sys_id=" + approval.sys_id;
}

// Construct email content
var emailContent = {};
emailContent.templateContent =
    "<div style='font-size:10pt; font-family:verdana;'>" +
    "Dear " + author + ",<br/>" +
    "<br/>" +
    "Knowledge Article: " + number + " has been rejected for publication. Please review the Approver's comments, adjust the article and re-send it for approval.<br/>" +
    "<br/>" +
    "Click here to review the rejected request: <a href='" + approval_link + "'>rejected request</a><br/><br/>" +
    "Short description: " + short_desc + "<br/>" +
    "<br/>" +
    "Article body: " + article_body + "<br/><br/>" +
    "Click here to view the article: <a href='" + article_link + "'>View Article</a><br/><br/>" +
    "<br/>";

 

Please mark helpful/correct if this helps you

View solution in original post

1 REPLY 1

sunil maddheshi
Tera Guru

@SomashekarB6490 

current.author might be a reference field, and you're trying to access first_name directly without ensuring it's a valid GlideRecord object.

 

var number = current.number;
var rejectNotes = "";
var short_desc = current.short_description;
var article_body = current.text;

var article_link = gs.getProperty('glide.servlet.uri') + "nav_to.do?uri=kb_knowledge.do?sys_id=" + current.sys_id;

// Initialize author variable
var author = "Unknown Author"; 

// Retrieve the revisor (if available)
var revisor = current.revised_by;
if (revisor) {
    var userRecord = new GlideRecord("sys_user");
    if (userRecord.get(revisor)) {
        author = userRecord.first_name;
    }
} else if (current.author) {
    var userRecord = new GlideRecord("sys_user");
    if (userRecord.get(current.author)) {
        author = userRecord.first_name;
    }
}

// Retrieve approval link
var approval = new GlideRecord("sysapproval_approver");
approval.addQuery("document_id", current.sys_id);
approval.addQuery("state", "rejected");
approval.query();

var approval_link = "#"; // Default value
if (approval.next()) {
    approval_link = gs.getProperty('glide.servlet.uri') + "nav_to.do?uri=sysapproval_approver.do?sys_id=" + approval.sys_id;
}

// Construct email content
var emailContent = {};
emailContent.templateContent =
    "<div style='font-size:10pt; font-family:verdana;'>" +
    "Dear " + author + ",<br/>" +
    "<br/>" +
    "Knowledge Article: " + number + " has been rejected for publication. Please review the Approver's comments, adjust the article and re-send it for approval.<br/>" +
    "<br/>" +
    "Click here to review the rejected request: <a href='" + approval_link + "'>rejected request</a><br/><br/>" +
    "Short description: " + short_desc + "<br/>" +
    "<br/>" +
    "Article body: " + article_body + "<br/><br/>" +
    "Click here to view the article: <a href='" + article_link + "'>View Article</a><br/><br/>" +
    "<br/>";

 

Please mark helpful/correct if this helps you