- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2020 03:45 AM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2021 02:41 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2020 06:03 AM
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:
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2020 07:11 AM
Hi Ankur,
We are updating data from AD , Why it is not updating same date which is coming from AD .
Thanks,
Khasim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2020 07:58 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2021 02:58 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader