- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2016 07:53 AM
I have an event called "knowledge.expiring" that I'd like to kick off every day (say at 7:00 a.m.) so that it looks to see if there are any knowledge articles that have a "Valid_to" date in 30 days. If they do, the event will fire a notification to the knowledge managers.
However, I don't know how to set up the script in the Scheduled Job to run that Event every day. I've read several different community articles about scheduled jobs and events and scripts, but none of them are tying them up for me.
In my Event, I have have conditions that are "Active" is True, "Workflow" is Published and "Valid_to" relative to 30 days from Now. Should those conditions have been in the Scheduled Job? My understanding is that I just want the job to go run the event every day and if the event finds any articles that meet the criteria it will fire off the notification.
I've also seen that there are other ways that developers have achieved this same sort of thing, and I am open to going an entirely different route...so, if you have a better idea, I'd love to hear that.
thanks,
Richelle
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2016 08:08 AM
I would go for what you are saying yourself:
I made the encoded query in the list view first to easy get your conditions. Not sure if you would need active is true. Is there any KB articles that are publish which isn't active?
anywhere, something like this inside your schedule job:
var gr = new GlideRecord('kb_knowledge');
gr.addEncodedQuery('workflow_state=published^active=true^valid_toRELATIVELE@dayofweek@ahead@30');
gr.query();
while (gr.next()) {
gs.eventQueue("knowledge.expiring", gr, gs.getUserID(), gs.getUserName());
}
I don't know what you want to send if param1 & param2 so I just took the OOB ones.
Then you just have a notification firing on the event itself.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2016 08:08 AM
I would go for what you are saying yourself:
I made the encoded query in the list view first to easy get your conditions. Not sure if you would need active is true. Is there any KB articles that are publish which isn't active?
anywhere, something like this inside your schedule job:
var gr = new GlideRecord('kb_knowledge');
gr.addEncodedQuery('workflow_state=published^active=true^valid_toRELATIVELE@dayofweek@ahead@30');
gr.query();
while (gr.next()) {
gs.eventQueue("knowledge.expiring", gr, gs.getUserID(), gs.getUserName());
}
I don't know what you want to send if param1 & param2 so I just took the OOB ones.
Then you just have a notification firing on the event itself.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2016 08:15 AM
So, I should remove the condition and any scripting from the Event and just have it run to trigger the notification...Should I set it to Run: Before and Run at: Server?
If I wanted to pass the Knowledge Article's "short_description" and the "valid_to" dates would I just modify those for the parameters?
thanks much,
Richelle
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2016 09:18 AM
I tested a quick one and this worked.
1. Register the event:
2. Create the encoded query we are going to use and copy that:
3. Create a schedule job and use the encoded query in the script:
4. Create the notification:
I just added the ${number} to show you how to put fields in the mail. you can have ${short_description} etc.
let me know if you still get stuck.
//Göran
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-16-2018 02:37 PM
This is helpful and does what I was looking for. I do have one question and issue though. I've created a custom field called 'Deputy' (reference to sys_user) and it will trigger the event and notifications but it is sending duplicate emails to users who are in that field more than once. It's almost like it can't read the oob business rule to consolidate these duplicate email notifications and send only 1. Is there a way (perhaps a group by in scheduled job script) to send only one notification per user? Here's my scheduled job script:
var gr = new GlideRecord('rm_product');
gr.addEncodedQuery('u_deputyISNOTEMPTY');
gr.query();
while (gr.next()) {
gs.eventQueue('product.notification', current, gs.getUserID(), gs.getUserName());
}
//I've also tried to add: gr.groupBy('u_deputy'); to the query but that didn't help.