Schedule Job for Knowledge Base articles based on last updated

lindac
Kilo Explorer

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

9 REPLIES 9

Try just "opened_by" without the "source." (both in the email and the scheduled script). As for the Email notification, the event.parm1 contains the sys_id of the user that should receive it.


lindac
Kilo Explorer

Hi Jim,

I made that change as you suggested, the event triggers but both parms are null. I have tried several variations of getting the opened by to work. The source field is on the kb_knowledge table which is referenced to the Task table and the opened_by is actually on the task table. So have tried task.source.opened_by, task.opened_by, source.task.opened_by. Everything is a complete failure.

Linda


Jim Coyne
Kilo Patron

I've reloaded the update set into demo022 for you to see it in action. The Scheduled Script would look like this:



//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("source.opened_by");
gr.query();
while(gr.next()) {
if (!gr.source.opened_by.isNil() &amp;&amp; gr.source.opened_by.toString() != lastAuthor) {
gs.eventQueue("u_knowledge.stale.article", gr, gr.source.opened_by.toString(), gr.source.opened_by.name.toString());
}
lastAuthor = gr.source.opened_by.toString();
}
}
})();


And the email would look like:



The following Knowledge Base articles, opened 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("source.opened_by=" + 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>


I had to remove

^sys_updated_on<javascript:gs.monthsAgoStart(36)
from the instance version because there just wasn't any appropriate data otherwise.

Now, that being said, I would highly suggest that you stay away from sending emails to the "source.opened_by" users because Incidents may be opened via email or the ESS portal (if you have it setup or will implement it). That opens up the real possibility that non-itil users will be receiving these emails. Imagine Joe Employee receiving an email telling him that he has an old Knowledge article when they have no idea what a Knowledge Article is? Or what to even do with it. 🙂

The person resolving or closing (depending on version of your instance) an Incident will be automatically tagged as the article's author. The author can even be changed to someone more appropriate later on. It makes a lot more sense to send it to them instead.


lindac
Kilo Explorer

Hi,
Once again I want to tell you THANK YOU for your assistance. Your last comment was the key. Hopefully they are satisfied with what you have given me.

Again thank you.


You are welcome