Schedule Job for Knowledge Base articles based on last updated
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-04-2013 01:21 PM
We have been given a request to create a schedule job that would send to the Submitted By of knowledge articles a list of all of their articles that have not been updated in more then 3 years.
Is this possible. I don't want to send them individual emails, which I believe is possible, because some of these users would get bombarded with emails. Can just one email with all of the articles that meet the timeframe doable?
Thank you for any assistance you can provide,
Linda
- Labels:
-
Knowledge Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-05-2013 09:39 AM
Thank you Jim for the quick reply.
I did apply your script to a scheduled job and create an email, but how do I get to the author and list of reports that just pertains to them within the email.
Your script is great and is definitely needed and but my biggest concern was getting a list that only pertains to that particular author.
Linda
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-05-2013 10:19 AM
Sorry, I forgot to attach the update set (it is there now). You can see the solution running on demo013 at the moment, but it will not be there much longer. Look for the email notification called "Stale Knowledge Article Reminder". Here is the contents of the Message field:
The following Knowledge Base articles, authored by ${event.parm2}, have not been updated in over 3 years:
<mail_script>
baseUrl = gs.getProperty("glide.servlet.uri") + "nav_to.do?uri=";
var gr = new GlideRecord("kb_knowledge");
gr.addEncodedQuery("author=" + event.parm1.toString() + "^workflow_state=published^valid_to>javascript:gs.daysAgoEnd(0)^sys_updated_on<javascript:gs.monthsAgoStart(36)");
gr.query();
while (gr.next()) {
template.print(gr.getDisplayValue('sys_updated_on') + " - <a href='" + baseUrl + gr.getLink() + "'>" + gr.getValue('number') + "</a> - " + gr.short_description + "
");
}
</mail_script>
Look for the Stale Knowledge label that has links to all three parts of the solution:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-05-2013 10:10 AM
1. an Event the email notification will fire from
2. A Scheduled Script Execution that will run everyday and fire the event when it finds stale articles
//runs every work day to check to see if there are any stale Knowledge articles
(function(){
//var gr = new GlideRecord("cmn_schedule");
//if (gr.get("name", "Stale Knowledge Articles")) {
// var schedule = new Packages.com.glide.schedules.Schedule(gr.sys_id);
// if(schedule.isInSchedule(new GlideDateTime())) {
_checkForArticles();
// }
//}
function _checkForArticles() {
var lastAuthor = "";
var gr = new GlideRecord("kb_knowledge");
gr.addEncodedQuery("workflow_state=published^valid_to>javascript:gs.daysAgoEnd(0)^sys_updated_on<javascript:gs.monthsAgoStart(36)");
gr.orderBy("author");
gr.query();
while(gr.next()) {
if (gr.getValue("author") != lastAuthor) {
gs.eventQueue("u_knowledge.stale.article", gr, gr.getValue("author"),gr.getDisplayValue("author"));
}
lastAuthor = gr.getValue("author");
}
}
})();
3. an Email Notification. You can add whatever you need to it.
All three parts are in the update set attached below. It will look for any Published article that is still valid (Valid to > Today) and has not been updated in over 3 years and sends 1 email to each Author with a list of all their articles.
The part that I have commented out in the Scheduled Script above is designed to check a Schedule to see if it should actually continue running or not. Just remove the "//" characters and add a Schedule with the dates you want the job to run on if you want that functionality. You could then set it up to run on the first work day of every quarter for example. It will run everyday the way it is now (not the best situation).
It works in both Berlin and Calgary releases, but I do need to find a replacement for the Packages.com.glide.schedules.Schedule call in Calgary as Packages calls are being "outlawed". 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-05-2013 05:42 PM
Hi Jim,
THANK YOU so much of your help. I applied the mail script to my notification and all worked well based on author. I realized they wanted source.opened_by and not author. Sorry about that. I substituted author in the scheduled job with source.opened_by and in the email notification I also substituted author for source.opened_by and the user field with source.opened_by. I received 1 email with all of the articles. It doesn't help I don't understand all of the pieces.
Initially I just had opened_by and received over a 100 emails each had the same articles over and over in each of the emails. I have also tried task.source.opened_by.
Should the user field in the Email Notification contain the field name or event.parm1?
Once again, thank you for all the assistance you have given me.
This my current scheduled script:
function _checkForArticles() {
var lastopenedby = "";
var gr = new GlideRecord("kb_knowledge");
gr.addEncodedQuery("workflow_state=published^valid_to>javascript:gs.daysAgoEnd(0)^sys_updated_on
gr.orderBy("source.opened_by");
gr.query();
while(gr.next()) {
if (gr.getValue("source.opened_by") != lastopenedby) {
gs.eventQueue("u_knowledge.stale.article", gr, gr.getValue("source.opened_by"),gr.getDisplayValue("source.opened_by"));
}
lastopenedby = gr.getValue("source.opened_by");
}
}
})();
This is my current mailscript:
baseUrl = gs.getProperty("glide.servlet.uri") + "nav_to.do?uri=";
var gr = new GlideRecord("kb_knowledge");
gr.addEncodedQuery("source.opened_by=" + event.parm1.toString() + "^workflow_state=published^valid_to>javascript:gs.daysAgoEnd(0)^sys_updated_on
gr.query();
while (gr.next()) {
template.print(gr.getDisplayValue('sys_updated_on') + " - " + gr.getValue('number') + " - " + gr.short_description + "
");
}