Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Clear DateTime field during Transform

Todd_Goodhew
Kilo Guru

Thanks in advance for any help. This one has me stumped.

I have a DateTime field on a target table.  During import, I want to clear this field of any value (make it NULL) during import based on the value of a corresponding source field.  

This should be pretty simple with a field map script on the transform, but no matter what I do, I can't seem to clear the target field of a value.  I can set it to another date/time value just fine.  I just can't seem to clear it of any value.

I know the source values exist in the source data and I know that part of the if statement passes true, previous version of the code had logging in it to validate this piece.

Any thoughts?

Here's the code:

answer = (function transformEntry(source) {

	var dtUtil = new DateTimeUtils();
	var value;
	
	// if the account is set to never expire or has no value, then clear out the field
	if ( source.u_accountexpires == '9223372036854775807' || source.u_accountexpires == '0' || source.u_accountexpires === undefined){
		value = '';  // return an empty string to clear out the value.
	} else {
	// otherwise convert the value from the MS Interger8 format to GlideDateTime format and set the target field with it
	value = dtUtil.int8ToGlideDateTime(source.u_accountexpires); 
	}

return value;
	
})(source);
10 REPLIES 10

sachin_namjoshi
Mega Patron

Please use below code to empty out date time field on your transform script.

 

 

target.<your_date_field_column_name> = 'NULL';

 

Regards,

Sachin

Todd_Goodhew
Kilo Guru

Thanks Sachin.  That worked.

However, I get this error message on each record:  Unable to format undefined using format string yyyy-MM-dd hh:mm:ss for field u_ad_account_expires

This expected?  

 

Another option is to do like below

 

target.u_ad_account_expires = '';

This should not cause any error

Regards,

Sachin

Todd_Goodhew
Kilo Guru

That clears the value, but still gets the same error.

Here's the current code.

answer = (function transformEntry(source) {

	var dtUtil = new DateTimeUtils();
	var value;
	
	// if the account is set to never expire or has no value, then clear out the field
	if ( source.u_accountexpires == '9223372036854775807' || source.u_accountexpires == '0' || source.u_accountexpires === undefined){
		//target.u_ad_account_expires = 'NULL';
		//target.setValue("u_ad_account_expires",'');
		target.u_ad_account_expires = '';
//		value = '';  // return an empty string to clear out the value.
	} else {
	// otherwise convert the value from the MS Interger8 format to GlideDateTime format and set the target field with it
	value = dtUtil.int8ToGlideDateTime(source.u_accountexpires); 
	}

return value;
	
})(source);