- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2018 09:21 AM
Hi,
I am trying to create an email that gets sent out when a knowledge article is created. This should be built off the sys approval table and go to the approver.
I have the email being fired off using these conditions:
when to send:
Table = Approval (sys approver_approval)
When source table = Kb_knowledge
Who will receive: approver
My problem is, I am trying to customize the subject & body text to pull in the Knowledge Article #
Here is what the approval record looks like:
I am trying a simple script in the subject field:
Docment ID = the name of the "Approving" field (to the right).. i've so tried "number", because that is the # of KB article.
When the email is triggered it only containts "has been submitted for approval" in the subject, it's not passing the KB#.
Can anyone help??
Thanks - the script i'm using is below
${sysapproval.document_id} ${sysapproval} has been submitted for approval
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2018 03:12 PM
Hey,
No worries 🙂
Everyone does it differently to be honest. You could have separate notifications to handle the different Publish/Retire scenarios (and build that into the conditions of the notifications) with their own specific wording, or you keep the one notification and pull through the scenario via mail script.
For example I've taken the mail script I provided you earlier and added the knowledge state line into it, so that it can pull through where it is in the knowledge article journey.
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
//Get the Knowledge Article object
var article = current.getValue('document_id');
var grKnowledgeArticle = new GlideRecord("kb_knowledge");
grKnowledgeArticle.addQuery("sys_id", article);
grKnowledgeArticle.query();
if (grKnowledgeArticle.next()) {
//Set the Subject of the Email to include the KB number
email.setSubject(grKnowledgeArticle.getValue('number') + ' has been submitted for approval');
//Push details into the body of the notification
template.print('Knowledge Number: ' + grKnowledgeArticle.getValue('number') + '<br/>');
template.print('Knowledge Category: ' + grKnowledgeArticle.getDisplayValue('kb_category') + '<br/>');
template.print('Knowledge State: ' + grKnowledgeArticle.getDisplayValue('workflow_state'));
}
})(current, template, email, email_action, event);
Here is my knowledge article, so it is KB0010001, in the category of "Announcements" and in the workflow state of "Review".
This then pulls through to my notification in the body.
You can apply logic into your mail script if you wish to display dynamic content based on the data you are pulling in from the knowledge article record.
Example below checks for the workflow state and displays additional text to help explain what this means to the approver.
if(grKnowledgeArticle.getDisplayValue('workflow_state') == 'Review'){
template.print(' (This approval is for the knowledge article to be published)');
}
else if(grKnowledgeArticle.getDisplayValue('workflow_state') == 'Pending retirement'){
template.print(' (This approval is for the knowledge article to be retired)');
}
Article is in a state of review
Article is in a state of pending retirement
Something to consider in your decision making on how you go about developing the solution (i.e. 2 notifications vs 1) is to consider the overhead of maintaining that design going forwards.
For example if you were to go with the 1 notification approach, there is a risk that any future changes you make impacts both scenarios of publish and retire - which doubles test effort for the change - where two notifications allows you that greater control to update one without impacting the other (removing the need to test both scenarios).
Personally I prefer to break things down into modular components. A mail script to get the data from the record and publishes that into the notification. A notification is made for each scenario, with customised text hardcoded into each but the mail script is called in each one. This allows us to easily make a change the mail script if anything impacts the knowledge data (e.g. need to add a new field into each approval email), of if we need to update the wording in the retirement email we can do that without worry of breaking anything.
TL;DR (Too Long; Didn't Read ^_^ - I have a habit of writing long replies)
There are a few different ways to do this and none of them are 'wrong', but you need to keep in mind how you want to maintain it going forwards too. I think you have the right approach by building a separate notification for each published state so you just need to build this into your conditions of the notifications so you only fire it once, and it'll have the right content.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-11-2018 11:36 AM
Hi Sandy,
You can update the mail script to basically write the content of your email for you, if you have a basic understanding of HTML.
Example below.
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
//Get the Knowledge Article object
var article = current.getValue('document_id');
var grKnowledgeArticle = new GlideRecord("kb_knowledge");
grKnowledgeArticle.addQuery("sys_id", article);
grKnowledgeArticle.query();
if (grKnowledgeArticle.next()) {
//Set the Subject of the Email to include the KB number
email.setSubject(grKnowledgeArticle.getValue('number') + ' has been submitted for approval');
//Push details into the body of the notification
template.print('Knowledge Number: ' + grKnowledgeArticle.getValue('number') + '<br/>');
template.print('Knowledge Category: ' + grKnowledgeArticle.getDisplayValue('kb_category'));
}
})(current, template, email, email_action, event);
It's basically the same mail script as before, the only difference now is that it prints two lines which both have a string label.
Notice how in the notification I am only calling the mail script (highlighted in red). I could add some other text around it but that part of the mail script will always print "Knowledge Number: <NUMBER>" and "Knowledge Category:<CATEGORY>" on separate lines.
As for the Approval/Rejection links these are called via mailto email templates. You simply need to add the links in as below:
To generate....
Hope that makes sense
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2018 08:54 AM
Hi Graham,
I can't thank you enough! This works great!
So now I am working on the notification that needs to go out when the state of a knowledge article is set to "Pending Retirement"..
What I am noticing is the same notification that we just created for the Publish Approval is being sent.
So I think I need to split out the notification, or create a separate one;
One for when the state of the Knowledge Article changes to "Review".. that means a user has clicked Publish.
And then another notification for when a person clicks "Retire", or the workflow sets the article to "Retire".
I am sorry to ask you so many questions, you just are very knowledgeable with this!
I appreciate your help!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2018 03:12 PM
Hey,
No worries 🙂
Everyone does it differently to be honest. You could have separate notifications to handle the different Publish/Retire scenarios (and build that into the conditions of the notifications) with their own specific wording, or you keep the one notification and pull through the scenario via mail script.
For example I've taken the mail script I provided you earlier and added the knowledge state line into it, so that it can pull through where it is in the knowledge article journey.
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
//Get the Knowledge Article object
var article = current.getValue('document_id');
var grKnowledgeArticle = new GlideRecord("kb_knowledge");
grKnowledgeArticle.addQuery("sys_id", article);
grKnowledgeArticle.query();
if (grKnowledgeArticle.next()) {
//Set the Subject of the Email to include the KB number
email.setSubject(grKnowledgeArticle.getValue('number') + ' has been submitted for approval');
//Push details into the body of the notification
template.print('Knowledge Number: ' + grKnowledgeArticle.getValue('number') + '<br/>');
template.print('Knowledge Category: ' + grKnowledgeArticle.getDisplayValue('kb_category') + '<br/>');
template.print('Knowledge State: ' + grKnowledgeArticle.getDisplayValue('workflow_state'));
}
})(current, template, email, email_action, event);
Here is my knowledge article, so it is KB0010001, in the category of "Announcements" and in the workflow state of "Review".
This then pulls through to my notification in the body.
You can apply logic into your mail script if you wish to display dynamic content based on the data you are pulling in from the knowledge article record.
Example below checks for the workflow state and displays additional text to help explain what this means to the approver.
if(grKnowledgeArticle.getDisplayValue('workflow_state') == 'Review'){
template.print(' (This approval is for the knowledge article to be published)');
}
else if(grKnowledgeArticle.getDisplayValue('workflow_state') == 'Pending retirement'){
template.print(' (This approval is for the knowledge article to be retired)');
}
Article is in a state of review
Article is in a state of pending retirement
Something to consider in your decision making on how you go about developing the solution (i.e. 2 notifications vs 1) is to consider the overhead of maintaining that design going forwards.
For example if you were to go with the 1 notification approach, there is a risk that any future changes you make impacts both scenarios of publish and retire - which doubles test effort for the change - where two notifications allows you that greater control to update one without impacting the other (removing the need to test both scenarios).
Personally I prefer to break things down into modular components. A mail script to get the data from the record and publishes that into the notification. A notification is made for each scenario, with customised text hardcoded into each but the mail script is called in each one. This allows us to easily make a change the mail script if anything impacts the knowledge data (e.g. need to add a new field into each approval email), of if we need to update the wording in the retirement email we can do that without worry of breaking anything.
TL;DR (Too Long; Didn't Read ^_^ - I have a habit of writing long replies)
There are a few different ways to do this and none of them are 'wrong', but you need to keep in mind how you want to maintain it going forwards too. I think you have the right approach by building a separate notification for each published state so you just need to build this into your conditions of the notifications so you only fire it once, and it'll have the right content.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2019 10:33 AM
Hi Graham,
Can you please share the approval decision mail script . Currently we are trying to display the notification to approver like below.
Kindly add a link “Click here to approve KB12345” - WIP
Kindly add a link “Click here to reject KB12345” - WIP
Kindly add a link “Click here to view the Approval Link: link
Please help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2018 05:27 AM
Perfect! Thanks for all the feedback. All of these suggestions worked great!