LDAP Transform Dates

kevin_cole
Kilo Contributor

I am needing to get the expiry date from AD into the sys_user table.   I have seen examples on here, but nothing seems to work for me

Anyone have an easy solution to do this?

Thanks

8 REPLIES 8

Cheyenne1
Kilo Guru

I just did this last month:



1.Create the expiry date field on the user form (date/time)



2.Navigate to your LDAP server


Add your AD expiry field name to the attributes section ( accountexpires)


Save



3.Navigate to your users transform map


Add a new field map


Target field ( your new field on the user form)


Date Format yyyy-MM-dd hh:mm:ss


Use Source Script = true



Script:


// 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_accountexpires === undefined) {
      // set a blank value if the source is 'undefined'
      target.setValue("your_user_form_expiry_date_variable", '');
} else if (source.u_accountexpires != 0) {
      // 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.toString());
      //log.info("ExpiresLocal: " + expiresLocal);
      // Set the value to the Local Time Zone value
      answer = expiresLocal
} else {
      // set a blank value if the source is anything else.
      target.setValue("u_expires", '');
}


Worked like a charm.  I had it all but the script part.  Thank you!

Cheyenne1
Kilo Guru

Did that work for you?


Hi Cheyennes,

 

I know this is very old post,

Can you assists on the Ldap date conversion.

I followed the steps suggested,still no Luck !

Any Suggestions?