I need to send notification to user on user anniversary.

niveditakumari
Mega Sage

Hi @Ankur Bawiskar

 

I'm executing my schedule job now and I'm able to see that in email logs it is sending email notification for user whom hire date is on 17th March ideally it should send notification to user whom hire date is on today 16th March but it is taking that user whom hire date is on tomorrow that is 17 March and sending notification to that user. I need to send notification to user when their anniversary date is completed and we are calculating anniversary date based on hire date and it should send notification user whom hire date is on today. 

It should calculate user anniversary for user whom hire date is on today that is 16th March but is calculating user anniversary whom hire date is on tomorrow that ids 17th March. 

I need to calcualte anniversary date on exact hire date. 

 

I have written script : 

Schedule job 

niveditakumari_0-1742121341083.png 

 

Please help me to correct that So that it will send notification to user whom hire date is on today only. 

 

Regards, 

Nivedita 

 

 

 

24 REPLIES 24

niveditakumari
Mega Sage

Hi @Medi C

 

Can you please tell how to get hire date correctly. 

Can we do +1 in that. 

 

Regards, 

Nivedita 

 

 

Hi @niveditakumari,

 

please try to_date.getDisplayValue() on your gs.log

 


If you found this helpful, please hit the thumbs-up button and mark as correct. That helps others find their solutions.

HI @Medi C

 

I have added code which you have mention above to get today date. 

I don't know which time it is taking in today date time. 

Please see below screenshot : 

niveditakumari_0-1742206339004.png

 

I have added schedule job time zone as 'Asia/Riyadh' because of that it is showing created as their today date time that is showing correctly but not sure about today date is printing which date. It seems that is an issue it is taking some other time. 

My profile time zone is same as 'Asia/Riyadh'. 

Can you please make me understand and correct that. 

 

Regards, 

Nivedita 

 

 

niveditakumari
Mega Sage

Hi @Medi C

 

I got one root cause for that. 

Please find attached screenshot : 

niveditakumari_0-1742209122506.png

 

niveditakumari_1-1742209176329.png

Here for above user in table('sys_user') it is showing hiring date is 17th March but in logs it is showing 16th March. 

One more thing when that schedule job is executing as per scheudle time then it is working as expected but when we are executing that manually then it is not working. It is sending notification based on user whom hiring date is on tomorrow. 

Can you please help me correct that why it is happening. 

 

Regards, 

Nivedita 

 

 

niveditakumari
Mega Sage

Hi @Ankur Bawiskar

 

Can you please help me with above. 

When I'm executing above code it is printing hire date wrong. 

Please find attached screenshot : 

niveditakumari_0-1742232779981.png

 

niveditakumari_1-1742232826002.png

For above user hiring date is 17th in table('sys_user') but in log it is showing 16th because my script is not working. 

var gr = new GlideRecord("sys_user");
gr.addQuery("active=true^u_hr_hire_dateISNOTEMPTY");
gr.query();
var c = 0;

while (gr.next()) {
    var jdate = new GlideDateTime(gr.u_hr_hire_date); // Parse u_hr_hire_date  
    var to_date = new GlideDateTime(); // Current date
    gs.info('hiring date for user is' + gr.name.toString() + jdate);  
    gs.info('hiring date is' + jdate);
    gs.info('hiring date day is' + jdate.getDayOfMonth());
    gs.info('hiring month is' + jdate.getMonthUTC());
    gs.info('today date is' + to_date.getDisplayValue());
    gs.info('today date day is' + to_date.getDayOfMonth());
    gs.info('today date month is' + to_date.getMonthUTC());

    // Compare day and month
    if (to_date.getMonthUTC() == jdate.getMonthUTC() && to_date.getDayOfMonth() == jdate.getDayOfMonth()) {
        c++;
        gs.log('count is' + c);
        gs.log("Hi, it's the user's joining date anniversary!" + gr.name.toString());
        gs.eventQueue("work.anniversary.notification", gr, gr.name.toString(), gr.email.toString());
    }
 
Can you please help me to correct that.
 
Regards, 
Nivedita