Send email to Knowledge Author when article is rejected

Sandy7
Tera Expert

Hi All,

I am really hoping someone can help.. I am trying to send an email to the Knowledge article author when their article is rejected.

It should go to the author and contain the comments for why it was rejected.

I tried building the notification on the sysapproval table but can't dot walk "author" in the who to send to section because knowledge isn't extension of task table.... I can select author but it gets sent to no one..

Can someone please help? It seems like this should be pretty standard functionality to send an email to author when their article is rejected...

thanks all!

1 ACCEPTED SOLUTION

Thanks - I will mark correct when I (hopefully) get it to work!

Appreciate your feedback very much!

View solution in original post

12 REPLIES 12

Did you ever get this to work? 

If so please mark correct so it won't show up as unaswered in the forum.

Hi Again -

I tried this script in a million different ways) and still can't seem to get it to work.. any tips?

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

//Get the Knowledge Article object
var article = current.sys_id;
var grKnowledgeArticle = new GlideRecord("sysapproval_approver");
grKnowledgeArticle.addQuery("document_id", article);
grKnowledgeArticle.query();
if (grKnowledgeArticle.next()) {


//Push details into the body of the notification
template.print(grKnowledgeArticle.getValue('comments') + '<br/>');

}
})(current, template, email, email_action, event);

You need to change the template.print row, usually you do 
current.comments.getJournalEntry();
but for some reason it doesn't work here with
template.print(grKnowledgeArticle.comments.getJournalEntry(-1) + '<br/>');

I can't get it to work, I tried to get another value and that worked fine, it's just the journal entry that seem to be an issue here. I'll see if I can find a solution for this

Now I actually got it to work when I changed the print row to be
template.print(grKnowledgeArticle.comments.getJournalEntry(1) + '<br/>');

The code you provided worked fine but need to change that row

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
	
	//Get the Knowledge Article object
	var article = current.sys_id;
	var grKnowledgeArticle = new GlideRecord("sysapproval_approver");
	grKnowledgeArticle.addQuery("document_id", article);
	grKnowledgeArticle.query();
	if (grKnowledgeArticle.next()) {
		//Push details into the body of the notification
		template.print(grKnowledgeArticle.comments.getJournalEntry(1) + '<br/>');
	}
	
})(current, template, email, email_action, event);

You'll get an issue with no line break after info about who rejected and the rejected comment.
You could fix this with javascript, use indexOf() to find out where (comments) position is (add 10 to that possition to get the position in the end) and substr() to use what is before/after.

I've got it to work now with only getting the actual comment made and cut out all the info about who rejected.

 

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
	
	//Get the Knowledge Article object
	var article = current.sys_id;
	var grKnowledgeArticle = new GlideRecord("sysapproval_approver");
	grKnowledgeArticle.addQuery("document_id", article);
	grKnowledgeArticle.query();
	if (grKnowledgeArticle.next()) {
		//Push details into the body of the notification
		var rejectComment = grKnowledgeArticle.comments.getJournalEntry(1);
		var posEnd = rejectComment.indexOf('(Comments)');
		posEnd = posEnd + 10; //Adding 10 to get the possition after (Comments)
		var substrComment = rejectComment.substring(posEnd);
		template.print(substrComment + '<br/>');
	}
	
})(current, template, email, email_action, event);