I need to send notification to user on user anniversary.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2025 03:36 AM
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
Please help me to correct that So that it will send notification to user whom hire date is on today only.
Regards,
Nivedita
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2025 11:38 AM - edited 03-17-2025 08:57 PM
Hello @niveditakumari
sys_user table records:
Your Code Results - The hire date timestamp is different as it is in GMT
Updated Code:
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 system date & time
// Get the date as per system time zone
var jdateDisplay = jdate.getDisplayValue();
var to_dateDisplay = to_date.getDisplayValue();
gs.info('Hiring date for user: ' + gr.name.toString() + ' | ' + jdateDisplay);
gs.info('Hiring date exact timestamp: ' + jdateDisplay);
gs.info('Hiring day: ' + jdate.getDayOfMonthLocalTime());
gs.info('Hiring month: ' + jdate.getMonthLocalTime());
gs.info('Today’s date: ' + to_dateDisplay);
gs.info('Today’s day: ' + to_date.getDayOfMonthLocalTime());
gs.info('Today’s month: ' + to_date.getMonthLocalTime());
// Compare day and month in local time zone
if (to_date.getMonthLocalTime() == jdate.getMonthLocalTime() &&
to_date.getDayOfMonthLocalTime() == jdate.getDayOfMonthLocalTime()) {
c++;
gs.log('Anniversary count: ' + c);
gs.log("Happy work anniversary, " + gr.name.toString() + "!" + '\n' + '\n');
gs.eventQueue("work.anniversary.notification", gr, gr.name.toString(), gr.email.toString());
}
}
Hope that helps!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2025 12:23 AM
Hi @Vishal Jaswal,
Thank you so much it is working as expected.
Can you please help me with birthday notification, same thing happeining in that and change that as you have done for anniversary and please make me understand what was the issue.
Please find my code :
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2025 12:49 AM
Hi @Vishal Jaswal,
My notification is working as expected.
Can you please make me understand what was the isuee and where exactly did you made changes for that.
Regards,
Nivedita
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2025 07:55 AM
Hello @niveditakumari
I assume the birthday notification is working as expected and you don't need further assistance, right?
From the hire date screenshot you shared earlier, I noticed that in your instance system property "glide.sys.date_form" has value "MM-dd-yyyy". This can mean that your background script is providing results as per the GMT timezone which is either ahead or behind the hire date
So, I added two variables to capture the displayValue() of u_hr_hire_date field and current date as shown below and then kept using these two variables in the remaining code.
var jdate = new GlideDateTime(gr.u_hr_hire_date); // Parse u_hr_hire_date
var to_date = new GlideDateTime(); // Current system date & time
// Get the date as per system time zone
var jdateDisplay = jdate.getDisplayValue();
var to_dateDisplay = to_date.getDisplayValue();
I would request you to please mark that specific message as Accepted Solution and if you won't mind then please mark helpfuls for all those messages who assisted here (I believe everyone).
Hope that helps!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2025 08:08 PM
can you try this
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader