- 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 11:24 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2024 11:30 PM
Hi @Sai_Charan_K,
I'm printing Jday,Jmonth. It is printing Jmonth correctly but in Jday it is taking day and time.
Can you please help me to correct that.
Regards,
Nivedita
- 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-16-2024 01:29 AM
Hi @Sai_Charan_K,
Thank you so much for all your help. It is working as expected.
It is printing correct in background script but when I'm executing that in schedule job manually it is not showing logs with notification subject line in emails and logs in events.
Can you please help me for that.
Regards,
Nivedita A
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2024 01:58 AM
Hi @niveditakumari ,
I think this is because of the cross scope privileges issues.
Did you try checking the giving the cross scope privileges? If not please do as you are access global scope data from HR scope. Please go to the table : sys_scope_privilege.LIST and check for the record with your schedule job name or create a new record under this table to allow the access.
Please mark this solution as "Helpful" and please mark it "Correct" and close the thread so that it benefits future readers.
Thanks and Regards,
K. Sai Charan
Sr. ServiceNow Developer
Deloitte India