- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2024 10:08 AM
Hi,
I need to send notification on employee work anniversary.
To achieve that I have created :
1. Event
2. Schedule Job
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2024 12:12 AM - edited 12-16-2024 12:37 AM
Hi @niveditakumari ,
Adjusted the code to below as I wasn't aware that your "Date Of Joining" field was not a date field.
var gr = new GlideRecord("sys_user");
gr.addQuery("active=true^u_date_of_joiningISNOTEMPTY"); // Query for active users with a joining date
gr.query();
while (gr.next()) {
var jdate = new GlideDateTime(gr.u_date_of_joining); // Parse u_date_of_joining
var to_date = new GlideDateTime(); // Current date
gs.print(jdate.getDayOfMonth());
// Compare day and month
if (to_date.getMonthUTC() == jdate.getMonthUTC() && to_date.getDayOfMonth() == jdate.getDayOfMonth()) {
gs.print("Hi, it's the user's joining date anniversary!");
gs.eventQueue("joining.notification", gr, gr.name.toString(), gr.email.toString());
}
}
Please try using this script and let me know if there are any further issues.
Please mark this solution as "Helpful" and "Accepted Solution" if this solution helped you in any way.
Thanks and Regards,
K. Sai Charan
Sr. ServiceNow Developer
Deloitte India
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-23-2024 01:25 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2025 08:47 AM
Hi @Sai_Charan_K,
It is sending notification who is completing their anniversary on tomorrow.
Ex - Today is 4th Jan and I'm executing schedule job today then it is checking for tomorrow's hire date and sending notification for that user who is completing their anniversary on 5th Jan.
Can you please help me to fix that.
Regards,
Nivedita
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2025 09:04 AM
Hi @niveditakumari ,
Can you please share the script and scheduled job conditions which you have used ?
Thanks and Regards,
K. Sai Charan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2025 01:58 AM
Hi @Sai_Charan_K,
I have tested that and found that after executing schedule job it is sending notification whose is completing anniversary on 3rd Jan. I need to send notification only for exact anniversary. It is sending notification to +1 day like when I'm executing that today it is sending notification for today + 1 that is completing their anniversary on 3rd Jan but it should send notification who is completing anniversary on today.
Please find attached screenshot :
Can you please help me to send notification for exact day.
Regards,
Nivedita
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2024 09:28 PM
you don't need to do this much string manipulation to get the month and day
simply use filter condition like this
var c = 0;
var gr = new GlideRecord('sys_user');
gr.addEncodedQuery('active=true^u_hr_hire_dateONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()');
gr.query();
while (gr.next()) {
c++;
gs.eventQueue('sn_hr_core.work.anniversary.notification', gr, '', gr.name);
}
gs.print('count is' + c);
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