- 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-15-2024 01:02 PM
You can probably try using Flow Designer; it will be much more easier.
then use Lookup Records and filter based upon the conditions you needed.
and then use the Action "send Email
If you have any questions, please feel free to ask.
Thanks and Regards
Sai Venkatesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2024 09:18 PM
Hi @niveditakumari ,
If you still wish to go with the scheduled job itself, please find the below script:
Scheduled Job:
var gr = new GlideRecord("sys_user");
//gr.addActiveQuery();
gr.addQuery("active=true^u_date_of_joiningISNOTEMPTY");
gr.query();
while (gr.next()) {
var jdate = gr.u_date_of_joining.toString();
var to_date = new GlideDateTime();//current day's date
var jday = jdate.split("-")[2]; //joining date
var jmonth=jdate.split("-")[1]; //joining month
if(to_date.getMonth().toString()==jmonth &&to_date.getDayOfMonth().toString()==jday){
gs.eventQueue("joining.notification",gr,gr.name.toString(),gr.email.toString());
}
}
Attached are the screenshots of the event logs that got triggered depending upon the joining dates of the user stored in user table.
This code is tested and works fine for me, So please do give it a try.
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-15-2024 11:10 PM
Hi @Sai_Charan_K,
I have used yourt code but it is not working.
Please find attached screenshot :
Notification(When to send)
Who will receive
Background Script print
Background Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2024 11:13 PM
Can you try printing jday and jmonth values in background script ?