Issues converting LDAP Attribute field whenCreated to Date/Time format
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2024 06:34 AM
Hello Guru's:
I'm hoping someone can direct me to the correct issue resolution.
I'm developing a Custom Table to Track our Service Account information.
I've been tasked to get these records to sync with AD and add a couple of key attributes to the table. (E.G. Domain, whenCreated, more to come).
I've hijacked our User LDAP transform and copied it to my new table.
I'm successfully creating new accounts and adding field information, like Distinguished Name.
I'm struggling, however, in getting the whenCreated field to properly convert to a Date/Time field.
I've seen several posts on this issue and have tried them and failed. Ones such as this:
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0960405
Either i get "Can't format" based on value - which turned out to be the date format used in the transform map.
Use Case using KB code:
whenCreated field = 20151007181608.0Z
My u_date_created value converts to 11/01/1599 21:01:18
I've even tried to parse the whenCreated field.
var myDate = "20191023204852.0Z";
var mdSub1 = myDate.substring(0,4);
var mdSub2 = myDate.substring(4,6);
var mdSub3 = myDate.substring(6,8);
gs.print("The SNOW date for is "+mdSub2+"/"+mdSub3+"/"+mdSub1+" 00:00:00");
This works in a background script giving me 10/23/2019 as the date. However, in the transform map script, it returns a date of 02/20/2019.
Any recommendations on what I've done wrong or how to get the right info.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2024 06:41 AM
please set the value in gdt and get the value in gdt
please share your transform script
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-06-2024 07:18 AM
My script in the transform field mapping is as follows (copied script from HI KB and updated it).
// This function converts the UTC date/time to local date/time
function getLocalTimeZoneDateTime(dateTimeUTC) {
var gdt = new GlideDateTime(dateTimeUTC);
return gdt.getDisplayValueInternal();
}
var dtUtil = new DateTimeUtils();
if (source.u_whencreated === undefined) {
// set a blank value if the source is 'undefined'
target.setValue(u_date_created,'');
} else if (source.u_whencreated != 0) {
// convert the date from int8 format to GlideDateTime in UTC
var whencreatedUTC = dtUtil.int8ToGlideDateTime(source.u_whencreated);
// convert the GlideDateTime in UTC to Local TimeZone
var whencreatedLocal = getLocalTimeZoneDateTime(whencreatedUTC.toString());
//log.info("WhencreatedLocal: " + whencreatedLocal);
// Set the value to the Local Time Zone value
answer = whencreatedLocal;
} else {
// set a blank value if the source is anything else.
target.setValue("u_date_created", '');
}