LDAP date field issue

Khasim Shaik1
Kilo Expert

Hi Team,

I am trying to update employee end in user table from AD (accountExpires) .  AD date value coming like "132590304000000000" this format So, I have converted this to date format using below script . 

Issue is updating one day ahead for few users 

Ex: user has employee end date of 2021-02-28 where the AD account is set to expire on 2021-02-27.

 

function getLocalTimeZoneDateTime(dateTimeUTC) {

var gdt = new GlideDateTime(dateTimeUTC);
gs.log("Date " + gdt);
return gdt.getDisplayValueInternal();
}
var dtUtil = new DateTimeUtils();
if (source.u_accountexpires === undefined) {
// set a blank value if the source is 'undefined'
target.setValue("u_employee_end_date",'');
} else if (source.u_accountexpires != 0) {
gs.log("source date" + source.u_userprincipalname + " :" + source.u_accountexpires);
// convert the date from int8 format to GlideDateTime in UTC
var expiresUTC = dtUtil.int8ToGlideDateTime(source.u_accountexpires);
// convert the GlideDateTime in UTC to Local TimeZone
var expiresLocal = getLocalTimeZoneDateTime(expiresUTC);
gs.log("Target date " +source.u_userprincipalname + " : " + expiresLocal);
//log.info("ExpiresLocal: " + expiresLocal);
// Set the value to the Local Time Zone value
//target.setValue("u_employee_end_date", expiresLocal);
} else {
// set a blank value if the source is anything else.
target.setValue("u_employee_end_date", '');
}

 

Thanks,

Khasim

1 ACCEPTED SOLUTION

Khasim Shaik1
Kilo Expert

I have fixed this issue with below article

The article also talks about the calculation issues with this being a day off

 

http://www.rlmueller.net/AccountExpires.htm

 

Thanks,

Khasim

View solution in original post

9 REPLIES 9

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Khasim,

the AD account expires date is always the end of the day i.e. Date 23:59:59

can you check below links; they may help you:

https://community.servicenow.com/community?id=community_question&sys_id=25fe0ba1dbdcdbc01dcaf3231f96...

https://community.servicenow.com/community?id=community_question&sys_id=56315fe9dbdcdbc01dcaf3231f96...

https://community.servicenow.com/community?id=community_question&sys_id=25fe0ba1dbdcdbc01dcaf3231f96...

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur,

 

We are updating data from AD , Why it is not updating same date which is coming from AD .

 

Thanks,

Khasim

Hi Khasim,

As you said it is happening for only few users; check what is the date of those users for which it is loading incorrect against those which are loading correctly

Regards

Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Khasim Shaik 

Thank you for marking my response as helpful.

If my response helped you please mark it correct to close the question so that it benefits future readers as well.

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader