Need to send an Email notification on last Monday of Month by Schedule job.

Sameeksha Sahu
Tera Contributor

Hello Team,

 

I need to send reminder mail monthly once on last Monday of month, could anyone suggest how to achieve this?

I have tried by making scheduled job conditional and writing the script but that i could do for 4th Monday of month, but as per user requirement i need to change this to last Monday.

 

Thank you in advance!

Regards,

Sameeksha

2 REPLIES 2

Community Alums
Not applicable

Hi @Sameeksha Sahu ,

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-1672141517637.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-1672141517601.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-1672141517244.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-1672141517628.gif

 

Hello Sandeep,

Thanks for your suggestion..

But here there is no dependency on the table like this..

I have to trigger the reminder notification to submit the time card on last Monday of month..

Is it possible to set the query in this scenario? If yes then how, could you please suggest?

Regards,

Sameeksha