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

This worked for me.  I was comparing the code and it appears identical

The only thing that comes to mind is to not include quotes around the 

target.setValue("your_user_form_expiry_date_variable", '');

so my field is u_expiry_date  therefore the statement is

target.setValue(u_expiry_date,'');

 

 

 

Kevin,

Thanks for the reply,

I followed the same steps as mentioned but no Luck.

 

Source Script:

answer = (function transformEntry(source)

{

function getLocalTimeZoneDateTime(dateTimeUTC)

{


var gdt = new GlideDateTime(dateTimeUTC);
return gdt.getDisplayValueInternal();


}


var dtUtil = new DateTimeUtils();


if (source.u_accountexpires=== undefined) {


target.setValue(u_expiration_date,'');


}

else if (source.u_accountexpires!= 0)

{

var expiresUTC = dtUtil.int8ToGlideDateTime(source.u_accountexpires);

var expiresLocal = getLocalTimeZoneDateTime(expiresUTC.toString());

answer = expiresLocal
}

else

{
target.setValue(u_expiration_date);    
}

})(source);

 

u_expiration_date ----> Field Created in User Table.

u_accountexpires -----> Ldap Field.

 

Can you suggest me with some inputs?

 

Do i need to create any Script include?

 

 

 

Kevin,

It would be great if you can post your code.

 

Thanks

kevin_cole
Kilo Contributor

Here is my code

 

//Expiry Date/Time

//answer = (function transformEntry(source) {
// For update set
// Add your code here
// 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_expiry_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_expires", '');
}

//})(source);