scheduled job for sending notification to all active user daily

aditya sharma2
Tera Contributor

Hello team,

 

We have requirement on creation of announcement we have to trigged one notification to all actives user on daily bases. Can someone help me on that .

 

Thanks in advance.

3 REPLIES 3

RaghavSh
Kilo Patron

Use announcement table, the announcement created there will be visible on portal for all users.


Raghav
MVP 2023

Community Alums
Not applicable

Hi @aditya sharma2 ,

about how to do this here:http://www.goranlundqvist.com/2016/03/fire-email-notification-from-schedule.html

Fire an email notification from a schedule job

 
This question popped up in the community and I thought I might as well put the answer here as well. Question was how you could check if the valid to date is 30 days from now and then send a notification to the KB managers.

First of all, you can find the community thread here: Schedule Job Script to Call Event
Now. The functionality that was wanted: When valid date is 30 days from now, the KB Managers should receive an email notification about it.

This can be solved with a schedule job which runs once a day and triggers an event for each KB article that matches the conditions and finally a notification is trigger of that event.

1. Register the event

First we need to register the event that we are going to put in the queue. This is done by going to the System Policy->Events->Registry.
 
Here we create a new event that looks like this:
SandeepDutta_0-1671115877025.gif

 

 
That was pretty easy, so let's head to the list view to get the encoded query.
 

2. Encoded Query

Quickest way is just to type kb_knowledge.list in the navigator and you get the to the list view of the KB articles. Set up the conditions and when you're done, right click and copy the query.
SandeepDutta_1-1671115877021.gif

 

 
 

3. Scheduled Job

Now we need to create the scheduled job which should once every day to see if there is any knowledge articles which is get close to the valid to date. This job goes through the encoded query and for each record it finds that matches the query it will fire of an event so the notifications can be sent. It looks like this and the code is below the picture.
 
SandeepDutta_2-1671115877023.gif

 

 
var gr = new GlideRecord('kb_knowledge');
gr.addEncodedQuery('workflow_state=published^active=true^valid_toRELATIVEEE@dayofweek@ahead@1');
gr.query();
 
while (gr.next()) {
gs.eventQueue("knowledge.expiring", gr);
}
 
As you can see in the gs.eventQueue we only have "gs.eventQueue("knowledge.expiring", gr)" in many cases you also specify parameters 1 & 2 like this: "gs.eventQueue(“incident.commented”, current, gs.getUserID(), gs.getUserName());". But since we don't need those, we just skip them.
 

4. Notification

Now we only have the notification left. Its pretty, simple. set that it will fire on the event and specify who will recieve it and finally the text for the notification. I'm just showing the section with the "when". The rest is purely case specified, but if there is any questions about it, just post a comment and I'll get back to you.
 
SandeepDutta_3-1671115877026.gif

 

Saurabh Gupta
Kilo Patron
Kilo Patron

Create an event on sys_user table.
Create a notification to be triggered based on event.
Write a scheduled job to fire the event on each active user.




Thanks and Regards,

Saurabh Gupta