Notification for an Expiring Knowledge Article
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2019 05:06 AM
Hi I would like to send an automatic message to the author 14 days before his article expires.
I've already found a script, but I don't really know how to use it and what event to create.
https://community.servicenow.com/community?id=community_question&sys_id=9778cb39db7adb4067a72926ca961999
Are there other and easier methods to solve this?
var ka = new GlideRecord('kb_knowledge');
ka.query();
while(ka.next())
{
var exp = new GlideDateTime(ka.exp_date).getDate(); //Considered exp_date as Article Expiry Date
if(exp.addDaysUTC(7)==new GlideDateTime().getDate())
{
gs.eventQueue('your_event_name',ka,gs.getUser()); //Include the recepients you require
}
}
//Running this Scheduled Job daily will send notification 7 days before the ExpiryDate
//You have to create a notification to be triggered when 'your_event_name' is triggered
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2019 05:23 AM
This is the best way to handle something like this. You would add this script to a scheduled Job. System definitions > Scheduled Jobs. You would then need to create an event under System Policy > Events > Register. You can call it anything you want. I try and make the name descriptive so in this case maybe something like kb.expiring.notification. The final step would be to create your notification and change on the "When to send" tab the filed "send when" to event is field. You may need to change to advanced view to see this field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2019 05:54 AM
Hello, thank you very much for your answer. I've tried it before, but it doesn't trigger the event at all. What else do I have to set in the event, besides the name?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2019 08:27 AM
I just took another peek at the code you provided and I'm not sure this line makes sense.
gs.eventQueue('your_event_name',ka,gs.getUser());
gs.getUser() pull the user interacting with system but since this is a scheduled job the part should be ka.author so it would look like this.
gs.eventQueue('your_event_name',ka,ka.author);
You would then need to make sure that on the "who will receive" tab that event param 1 contains recipient is checked.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2019 05:37 AM
Hi,
This script is pretty straight forward. You would first create your event by going to System Policy > Registry, you can name it anything you like or follow your developer/sys admin naming convention if they have one. Then go to System Notification > Notifications and create a new notification. On the first tab, "when to send": you would select "Send When" and choose "Event is Fired" then select your event that you just made from the drop-down list, then on second tab: who will receive, check the boxes for "Parm 1 Recipient" and "Send to Creator", on the third tab...write out what you want to say to the person receiving it.
Now, finally, go to System Definition > Scheduled Jobs and create a new scheduled job. I would run this daily at whatever time you'd like, simply paste the code you have above in the scheduled job script section and change:
if(exp.addDaysUTC(7)==new GlideDateTime().getDate())
to
if(exp.addDaysUTC(14)==new GlideDateTime().getDate())
and
gs.eventQueue('your_event_name',ka,gs.getUser()); //Include the recepients you require
'your_event_name'
to whatever your event name is that you created just moments ago.
Also, finally, I would change the gs.getuser() from this line to ka.author as the getuser there is scripted incorrectly and that's probably why it's not working.
Please mark reply as Helpful/Correct. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!