- 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-17-2022 06:47 AM
Hi Deepika,
why comments are deleted?
Regards,
Pavankumar
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā09-17-2022 04:25 AM
Hello
Please check if the below script helps to trigger the Happy Birthday email on the date of user's birthday:
(function () {
var gdt = new GlideDateTime(); //get today's date time
var todayDate = gdt.getDate(); //get today's date
gs.info("today date: " + todayDate); // check logs on System logs --> All
var query = "u_birthdayON" + todayDate +"@javascript:gs.dateGenerate('" + todayDate + "','start')@javascript:gs.dateGenerate('" + todayDate + "','end')";;
var userRecordGR = new GlideRecord('sys_user');
userRecordGR.addActiveQuery();
userRecordGR.addEncodedQuery(query);
userRecordGR.query();
while (userRecordGR.next()) {
gs.eventQueue('happy_birthday', userRecordGR, userRecordGR.getUniqueValue() ,''); //check event name
}
})();
If my answer helped you in any way then please do mark it as helpful. If it answered your question then please mark it correct and helpful. This will help others with similar issue to find the correct answer.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā09-19-2022 10:58 PM
Hello
Just wanted to check with you, if the above response answered your question. If yes, then please do close this thread/question by marking the appropriate response as correct.
Thanks