Schedule Job Script to Call Event

richelle_pivec
Mega Guru

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

1 ACCEPTED SOLUTION

Goran WitchDoc
ServiceNow Employee
ServiceNow Employee

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.


View solution in original post

9 REPLIES 9

Thank you. This worked perfectly. I removed the Condition and Advanced script from my Event Business Rule and left it to Run at Server. I left Insert and Update checked.


Your script was exactly what I needed.



Thanks,



Richelle


I had to make one small change to the code you provided. It was returning all knowledge articles with a Valid_To date within 30 days...past or future.



I changed this: gr.addEncodedQuery('workflow_state=published^active=true^valid_toRELATIVELE@dayofweek@ahead@30');


to this: gr.addEncodedQuery('workflow_state=published^active=true^valid_toRELATIVEEE@dayofweek@ahead@30');



And now it brings back just the articles that are "valid_to" exactly 30 days from today...which will allow me to have it run every day and send only to those that are 30 days out.



thanks again,



Richelle


ahh nice.. I didnt have so many KB to play around with in the dev environment 😃 and I think relative is a pain in the ## ¤"% ¤..



Glad you got it to work, I got some nice pictures for you 😃


Nilanjan1
Mega Sage

Hello All, 

I was going through the post and it seems to be very helpful, I am also trying to create a kind of a notification which triggers every year on a list of cloud applications business owners . I created a scheduled jobs and an event and a notification, however when the execute a scheduled job the firing of the event or the notification is not happening. Any leads to this. this is what I have used as a steps: 

 

var gr = new GlideRecord('u_cloud_applications');
gr.addEncodedQuery('u_business_ownerISNOTEMPTY');
gr.query();
while(gr.next()){
	gs.eventQueue('Cloud Application Notification',gr);
}

cloud application notification is the Event. 

Regards

Nilanjan

preethika2
Tera Contributor

For me the event is getting triggered, 

But I not receiving the notification that is being triggered.

How to link the notification with the schedule job to trigger the notification.