Hello everyone, iam trying to send birthday notification using schedueld job but its not working

Rajashekar  1
Tera Contributor

var today = new GlideDateTime();


var currentMonth = today.getMonth();


var currentDay = today.getDayOfMonth();

 

gs.info("Current Month: " + currentMonth);


gs.info("Current Day: " + currentDay);

 

var gr = new GlideRecord('sys_user');\
gr.addActiveQuery();
gr.query();

while (gr.next()) {

var dob = new GlideDate(gr.u_date_of_birth);
//var dob = gr.u_date_of_birth;
var dobMonth = dob.getMonth();
gs.info("dob" + dob);

gs.info("dobMonth" + dobMonth);
var dobDay = dob.getDayOfMonth();
gs.info("dobDay" + dobDay);


if (dobMonth == currentMonth && dobDay == currentDay) {
var user = gr.getDisplayValue('name');
var email = gr.email;


gs.eventQueue('birth.day', gr, email, user);
}
}

 

here we iam trying to get current month and date but not the year so it matches the month and date the notification should be trigger to user.

 

Root cause of JavaScriptException: java.lang.NullPointerException
: java.lang.NullPointerException: java.base/java.util.Calendar.setTime(Calendar.java:1800)
com.glide.glideobject.GlideDateTime._getMonth(GlideDateTime.java:1862)

 

iam getting this error please help with the code

 

 

 

 

4 REPLIES 4

Amit Verma
Kilo Patron
Kilo Patron

Hi @Rajashekar 1 

 

The custom field u_date_of_birth is of type datetime or it is a string field ?

 

Thanks and Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.

u_date_of_birth type is Date type and tried using date and time to but no luck

@Rajashekar 1 

 

Did you got a chance to look on the below post. It will be a pure  no-code and efficient approach :

https://www.servicenow.com/community/itsm-forum/birthday-email-notification/td-p/669497

 


Please mark this response as correct and helpful if it assisted you with your question.

Amit Pandey
Kilo Sage

Hi @Rajashekar 1 

 

Can you try this once-

 

var dob = new GlideDateTime(gr.u_date_of_birth);

 

Also, would recommend you to use flow designer. The link shared my Mr. @Amit Verma will help you configure that.

 

Regards,

Amit