The CreatorCon Call for Content is officially open! Get started here.

accountExpires attribute import to User Table

Cory Hitchings
Giga Guru

Hi all, 

I've been trying to import the accountExpires attribute from AD into ServiceNow sys_user table and having some issues with the date format. 

I have a new field on the sys_user form called u_end_date in a Date/Time variable with a limit of 100.  

Our AD date format appears like this:  

find_real_file.png

(Month/Day/Year) (Hour:Minutes:Seconds) (AM/PM) (Timezone)

Looking at this, it leads me to believe the format should be: 

mm/dd/yyyy hh:mm:ss a z

However; when I run the LDAP User import, it errors on each individual with an accountExpires date with this message: Unable to format undefined using format string MM/dd/yyyy hh:mm:ss a z for field u_end_date 

Here is my script for accountExpires Field Map: 

answer = (function transformEntry(source) {
	// 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(u_end_date,'');
} 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_end_date",'');
}

// 	return ""; // return the value to be put into the target field

})(source);

I've tried the following but out success with any of these variations:

MM/dd/yyyy hh:mm:ss
yyyy/dd/MM hh:mm:ss

MM/dd/yyyy hh:mm:ss a
yyyy/dd/MM hh:mm:ss a

MM/dd/yyyy hh:mm:ss z
yyyy/dd/MM hh:mm:ss z

MM/dd/yyyy hh:mm:ss a z
yyyy/dd/MM hh:mm:ss a z

Any ideas what date format this should be configured as?  Thanks so much in advance! 

1 ACCEPTED SOLUTION

Mike Patel
Tera Sage

I use below to onBefore transform script to import that from AD. (Make sure to remove field mapping)

// Updates the SN Account Expires field   
var n = source.u_accountexpires;  
var s = n.toString();  

// Only convert AD accountExpires values that begin with 1 (ex. 0 represents never expires)  
if (s.charAt(0) == 1) {  
	var dtUtil = new DateTimeUtils();
	var gDate = dtUtil.int8ToGlideDateTime(n);
	gDate.addDaysLocalTime(-1);
	target.u_account_expires = gDate;  
}else if(!target.u_account_expires.nil()) {  
	target.u_account_expires = '';  
}  

find_real_file.png

View solution in original post

24 REPLIES 24

go to transform map and look at source table name then on LHN search for that table like ldap_user.list then open one of the records and right click on the field and show.

Thank you Mike, I thought I replied but doesn't look like it went through. 

I am able to see accountExpires populating on the import, however this is still not translating back to the sys_user u_end_date field.  

find_real_file.png

Can you share screenshot of the script and verify the field name on source table.

You bet, here is the script: 

find_real_file.png

Confirming that accountExpires exists with data here on the ldap_import.list view: 

find_real_file.png

If you on Paris then it's known issue. You can follow work around mentioned on article below.

https://hi.service-now.com/kb_view.do?sysparm_article=KB0860677

For Customers upgrading to Paris Patch 2 and above

Some customers upgrading to PP2+ who have customized Script Include (name = "DateTimeUtils") will require resolving conflict for the file sys_script_include_3aa1185ec0a80a68523ad51b6fe97328.xml.

1. Navigate to Upgrade Center > Upgrade History.
2. Search for File name = "sys_script_include_3aa1185ec0a80a68523ad51b6fe97328" in the related list "Customizations Unchanged" or "Skipped Changes to Review".
3. Refer to product doc on resolving the conflicts.

For Customers on Pre Paris Patch 2: 

As a workaround, update int8ToGlideDateTime function in the Script Include "DateTimeUtils" to following

int8ToGlideDateTime: function(int8Date) {
        function fileTimeToEpoch(filetime) {
            filetime = filetime / 10000;
            filetime = filetime - 11644473600000;
            return filetime;
        }
        var gdt = new GlideDateTime();
        gdt.setNumericValue(fileTimeToEpoch(int8Date));
        return gdt;
    }