
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2019 04:02 AM
As stated in the title.
We are using ServiceNow for a couple of years now, and our knowledge bases are expanding in content and number. We want to be updated on knowledge items that are getting close to their valid date (within 30 days) and have an automatic email sent to the owner of that knowledge base.
I could create a scheduled job and let it check all the knowledge items but that would send a notification for every item, like in this community post. Since we'll be having well over 100 items expiring early 2020, and we dont want to get that many emails every monday or so.
Can I open an email and add text to it, and send it when the scheduled job is finished? What we want is a single email to the owner/group of each knowledge base. In the email I want a list with knowledge numbers, short description and valid date, only of the knowledge items that will expire in the next 30 days.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2019 04:55 AM
HI Bart,
We did something similar in our environment. We have 3 knowledge bases, each w/ 100-300 articles in each. We have 3 scheduled jobs, one for each knowledge base. First, you'll want to grab the URL of the filter by going to the kb_knowledge list and applying a filter like this:
Once you grab the URL (right click URL and select Copy URL, create a scheduled job. Here is what ours looks like:
Next create an event. Our event is called 'knowledge.articles.expiring.customerService'
Then create an email notification which is fired by an event
In the When to send tab, ensure the Advanced condition is 'answer = true;'
In the Who will receive, add your recipients
In the What it will contain, point to an email template.
In the template, in the Message HTML, you'll want to include a mail_script. The mail script will look like this:
(function runMailScript(current, template, email, email_action, event){
var article = new GlideRecord('kb_knowledge'); //create a query to retrieve knowledge articles
article.addEncodedQuery('workflow_state=published^valid_to<=javascript:gs.endOfNextMonth()^kb_knowledge_base=05ff44289f011200550bf7b6077fcfa3');
//only retrieve articles that are published and valid to next month and are assigned to knowledge base Customer Service
article.query();
while(article.next()){
template.print....
<add your content here>
}
}})(current, template,email, email_action,event);
Hope this helps. Feel free to ask any questions.
Oh, you'll need to create a scheduled job for each knowledge base and an event for each knowledge base and a notification for each knowledge base

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2019 04:55 AM
HI Bart,
We did something similar in our environment. We have 3 knowledge bases, each w/ 100-300 articles in each. We have 3 scheduled jobs, one for each knowledge base. First, you'll want to grab the URL of the filter by going to the kb_knowledge list and applying a filter like this:
Once you grab the URL (right click URL and select Copy URL, create a scheduled job. Here is what ours looks like:
Next create an event. Our event is called 'knowledge.articles.expiring.customerService'
Then create an email notification which is fired by an event
In the When to send tab, ensure the Advanced condition is 'answer = true;'
In the Who will receive, add your recipients
In the What it will contain, point to an email template.
In the template, in the Message HTML, you'll want to include a mail_script. The mail script will look like this:
(function runMailScript(current, template, email, email_action, event){
var article = new GlideRecord('kb_knowledge'); //create a query to retrieve knowledge articles
article.addEncodedQuery('workflow_state=published^valid_to<=javascript:gs.endOfNextMonth()^kb_knowledge_base=05ff44289f011200550bf7b6077fcfa3');
//only retrieve articles that are published and valid to next month and are assigned to knowledge base Customer Service
article.query();
while(article.next()){
template.print....
<add your content here>
}
}})(current, template,email, email_action,event);
Hope this helps. Feel free to ask any questions.
Oh, you'll need to create a scheduled job for each knowledge base and an event for each knowledge base and a notification for each knowledge base

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2019 05:09 AM
Thanks for your extensive reply! Of course creating a scheduled job and event and notification solves the issue of getting the right information to the right knowledge base owner.
I'm gonna try my hand at this. Will reply if I run into anything else!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2019 07:18 AM
Hey Matthew, I have two questions.
What kind of line do you have where it says <add your content here> ? This is where you add the list of knowledge items correct?
In the Notification in the tab "When to send" I cant select the Event name of the Event I just created. Its simply not in the list.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2019 09:05 AM
Hey Bart,
The <add your content here> would be stuff relevant to your articles. So here is what we display:
(function runMailScript(current, template, email, email_action, event){
var article = new GlideRecord('kb_knowledge'); //create a query to retrieve knowledge articles
article.addEncodedQuery('workflow_state=published^valid_to<=javascript:gs.endOfNextMonth()^kb_knowledge_base=05ff44289f011200550bf7b6077fcfa3');
//only retrieve articles that are published and valid to next month and are assigned to knowledge base Customer Service
article.query();
while(article.next()){
template.print('<body>');
var baselink = gs.getProperty('glide.email.override.url');
template.print('<strong'+'<a href="'+baselink _ '?uri=kb_knowledge.do?sys_id='+article.sys_id+ ':>' + article.number _ '</a></strong>'); //here is where we call the sys_id of the first article we are trying to display. baselink the url specific for your instance. for example, in our dev env't, our baselink is https://oursitdev.com/. This way you are not having to change your code when this gets pushed to test and then to prod. The baselink property is unique to each of your env'ts.
template.print('<br/>');
template.print('<strong>Article title: ' + '</strong>' + article.short_description);
template.print('<br/>');
***You can continue to add to this list of whatever you want to send in your email***
}
}})(current, template,email, email_action,event);
I'd copy everything from our script but we are self-hosted so I can't copy/paste unfortunately.
For the event, when creating it, make sure the table is kb_knowledge and when you create your notification, ensure the table selected in the notification is kb_knowledge as well.
Hope this helps-
Matthew