- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-06-2014 04:14 PM
I have been tasked to setup a notification in our instance to periodically search the Knowledge Base for articles that are set to expire in 30 days or less, and then notify the author of the article with an email notification letting them know to update/retire the article. So far as I have found in the forums, the best way to accomplish this is to setup a Scheduled Job script to periodically search the KB table for articles meeting the conditions, and within this script kickoff an event. Also, there is an email notification that fires off when this event occurs. I have done this in my dev instance, and according to my event logs, the event kicks off and collects the right info in the event parameters, but the email notification still is not being sent. They are all running off of the Knowledge table, but I'm not sure why the email does not get sent ( continuously check the Outbox for the emails because sending is turned off in my dev instance. Any suggestions? I have the scripts available if anyone cares to take a look.
Screenshots added as requested Message was edited by: Chris Hoff
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-07-2014 08:33 PM
Hi Chris,
I would suggest you try with a simple Notification first and then try Mail Scripts if the first on works.
Then, there is no need of gr.update().
Third:- Pass gr.author as parm1 and gr.number as parm2(without the display values).
Thanks,
Subhajit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2014 12:29 AM
notify();
function notify(){
var authorarray = '';
var author_gr = new GlideRecord('kb_knowledge');
author_gr.addEncodedQuery("workflow_state=published^valid_to<=javascript:gs.beginningOfNextMonth()");
author_gr.query();
while(author_gr.next())
{
if(authorarray =='')
{
authorarray =author_gr .author;
}
else
{
authorarray = authorarray +','+author_gr .author;
}
}
gs.eventQueue("re.knowledge", author_gr, authorarray);
author_gr.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-11-2015 10:09 AM
The code you wrote, where would I put that? In the event?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-11-2015 01:11 PM
Got it to work!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-12-2015 05:42 AM
One quick question though. I GOT the code to work BUT I have been tasked with sending notifications a month before AND a week before. I have 2 email notifications---one for the month and one for the week. My problem is when I execute the code for either one, I get the desired results, BUT more info than I need.
My code for next month is this---
doit();
function doit() {
var gr = new GlideRecord('kb_knowledge');
gr.addEncodedQuery("workflow_stateNOTINdraft, review, retired^valid_to>=javascript:gs.beginningOfToday()^valid_to<=javascript:gs.beginningOfNextMonth");
gr.query();
while (gr.next()) {
gs.eventQueue('kb.valid.check', gr, gr.getDisplayValue('author.email'), gr.getDisplayValue('valid_to'));
gr.update();
}
}
Whenever I execute it It gives me anything that is valid_to passed today..all I want though is things greater than today AND less than a month from today. But it is giving me things 5 years from today. It's the same thing for my next week script. except I have beginningOfNextWeek. How do I fix this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-12-2015 08:20 AM
You will want to modify the string in the gr.addEncodedQuery() line. Take a look at this wiki article section - Encoded Query Strings - ServiceNow Wiki
It explains how to create the encoded query by filtering a list of records and then copying the breadcrumb. This way you can filter down the records to what you need and then copy/paste the query into the code. You'll probably want to build a filter like this for the next week report:
And this for the next month report:
You may or may not want the last part of the filter. It filters out articles that expire next week in order to avoid dupes in your reports. All depends on when you run them.