- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2025 04:00 AM
Hi,
I have to send birthday notification to employee. I have written schedule job script and date of birth is type as date field. I have tested that script and I'm able to get birthday, birthday day, birthday month value, it seems it is having issue while checking if condition.
Please find below script and correct that :
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2025 11:46 PM
to verify this in HR scope.
Create fix script in HR Core scope and see if the script works
Also don't use gs.log(), it won't work in scoped app, use gs.info()
var gr = new GlideRecord("sn_hr_core_profile");
gr.addQuery("user.active=true^date_of_birthISNOTEMPTY");
gr.query();
while (gr.next()) {
var bdate = gr.date_of_birth.toString();
var to_date = new GlideDateTime(); // current day's date
var bday = bdate.split("-")[2]; // birthday date
var bmonth = bdate.split("-")[1]; // birthday month
gs.info('birthday is' + bdate);
gs.info('today date is' + to_date);
gs.info('birthday day is' + bday);
gs.info('birthday month is' + bmonth);
// Adjust month comparison to account for zero-based index
if ((to_date.getMonthLocalTime()) == parseInt(bmonth) && to_date.getDayOfMonthLocalTime() == bday) {
c++;
gs.info('count is here' + c);
gs.info("Hi, it's the user's birthday! for " + gr.user.name);
gs.eventQueue("sn_hr_core.birthday.notification", gr, gr.user.name.toString(), gr.user.email.toString());
}
}
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2025 11:33 PM
Hi @Ankur Bawiskar,
Yes, users are available on that day in HR Profile table.
Can you please check below code :
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2025 11:39 PM
Hi @Ankur Bawiskar,
I'm executing above code in background script and it is showing error :
It seem we need to create application restricted access for that.
Can you please help me to create that.
Regards,
Nivedita
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2025 11:46 PM
to verify this in HR scope.
Create fix script in HR Core scope and see if the script works
Also don't use gs.log(), it won't work in scoped app, use gs.info()
var gr = new GlideRecord("sn_hr_core_profile");
gr.addQuery("user.active=true^date_of_birthISNOTEMPTY");
gr.query();
while (gr.next()) {
var bdate = gr.date_of_birth.toString();
var to_date = new GlideDateTime(); // current day's date
var bday = bdate.split("-")[2]; // birthday date
var bmonth = bdate.split("-")[1]; // birthday month
gs.info('birthday is' + bdate);
gs.info('today date is' + to_date);
gs.info('birthday day is' + bday);
gs.info('birthday month is' + bmonth);
// Adjust month comparison to account for zero-based index
if ((to_date.getMonthLocalTime()) == parseInt(bmonth) && to_date.getDayOfMonthLocalTime() == bday) {
c++;
gs.info('count is here' + c);
gs.info("Hi, it's the user's birthday! for " + gr.user.name);
gs.eventQueue("sn_hr_core.birthday.notification", gr, gr.user.name.toString(), gr.user.email.toString());
}
}
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2025 12:08 AM
Hi @Ankur Bawiskar,
I have tested above code in fix script and found that it is generating event in event log but not printing log statement and not sending notification.
Please find below screenshot :
1. Generating event
2. Script log statement
3. Email log
I don't have much idea on fix script.
Can you please help me to fix that and make it work.
Regards,
Nivedita
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2025 12:21 AM
Glad to know that my script worked.
Seems you are sending user's email in 2nd parameter.
So in notification ensure Event parm2 contains Recipient checkbox is True
I believe I have provided answer to your question. Further debugging of event, notification etc you can perform based on your experience and developer skills.
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