- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā09-16-2022 01:14 PM
I've created birthday (u_birthday) field in user table (sys_user) which stores users birth date.
I want to send emails to the users whose birthday is in this month only.
var users = new GlideRecord('sys_user');
users.addActiveQuery();
users.query();
while (users.next()){
var birthDay = new GlideDate(users.u_birthday);
var BMonth=birthDay.getMonthNoTZ();
if(BMonth == "9"){
gs.eventQueue('happy_birthday', users, users.sys_id);
}
}
this is the script I've written but it's not working.
I think there is problem in fetching the value from birthday field in users table. Please help me resolve it.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā09-16-2022 10:59 PM
Hi,
when you are triggering schedule job and try it run On demand?
select one user birthday in this month
var gdt = new GlideDate(); //current date
var currentmonth = gdt.getMonthLocalTime(); //get current month
gs.info("current month " +currentmonth); // check logs on this module system logs>System Log>All
var users = new GlideRecord('sys_user');
users.addActiveQuery();
users.query();
while (users.next()) {
var birthDay = new GlideDate(users.u_birthday); //get birthday date
var bdaymonth = birthDay.getMonthLocalTime(); //get birthday month
gs.info("birthday month " +bdaymonth);//check logs on this module system logs>System Log>All
if (bdaymonth == currentmonth) { //compare current month with birthday month
var sysid = JSON.stringify(users.sys_id);
gs.eventQueue('happy_birthday', users, sysid ,''); //check event name
}
}
using above script check the logs on current and birthday month.
Thanks,
Pavankumar
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā09-16-2022 11:05 PM
Yes, you can use daily or monthly but to test the script you need to run it once.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā09-16-2022 11:08 PM
For Above script should I run it once or on demand or daily? for current testing purpose
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā09-16-2022 11:16 PM
to do testing we need once user whose birthday on this month.
if there is no user with that it will not send email so try to add for user as birthday this month (any date of this month).
So, we have one user then on scheduled job select Run as Once and save. Click on Execute Now Ui action on form.
Once it is executed check the logs and emails as well.
on the Emails module you can see all the emails which are triggered and check your email whether it sent or not.
If it is working then you can Run the scheduled job as per the requirement(daily, weekly, monthly or any).
Thanks,
Pavankumar
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā09-16-2022 11:20 PM
Tried exactly in logs only current month is showing not picking up birthday month from users table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā09-16-2022 11:32 PM
Hi,
everything is on global scope is that right?
what value you are getting on birthday month log it share the error?
birthday field type is date is it correct and if yes check backend name and configure the field and share screenshot?
Thanks,
Pavankumar
ServiceNow Community MVP 2024.
Thanks,
Pavankumar