Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Populate last day of month of hire date and time should be 23:00

lucky24
Tera Contributor

Hi Team,

I am working on HRSD and I have to populate the "due date" for one task which should be the last day of the "hire date" and the time should be 11:00 pm according "subject person" time zone.

subject person - reference field and referring to user table

hire date - date field

due date - date time field

var task = new GlideRecord("sn_hr_core_task");
task.addQuery("sys_id","13a59a561ba0c650b862ed34604bcb7f");
task.query();
if(task.next()){
var timezone = task.parent.subject_person.time_zone;
var hiredate = task.parent.subject_person.u_onboarding_hire_date;
}
 
var hireDate = new GlideDateTime(hiredate);
hireDate.setTimeZone(timezone);
var hireMonth = hireDate.getMonthLocalTime(); // Get the month of the hire date
var hireYear = hireDate.getYearLocalTime(); // Get the year of the hire date
// Set the due date to the last day of the hire date's month at 23:00
var eom = new GlideDateTime();
eom.setYearLocalTime(hireYear);
eom.setMonthLocalTime(hireMonth + 1); // Move to the next month
eom.setDayOfMonthLocalTime(1); // Set to the first day of the next month
eom.addDaysLocalTime(-1); // Subtract one day to get the last day of the hire month
 
gs.print(eom);
var lastdate = eom.getDate() + " 23:00:00";
gs.print(lastdate);
 

I am trying with the above code but I am getting UST time for each time zone user.

I want to set the last day of the month of hire date according subject person's time zone

Can someone guide me on how can I achieve this requierment ?

0 REPLIES 0