Clear DateTime field during Transform
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2018 11:11 AM
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);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2018 11:14 AM
Please use below code to empty out date time field on your transform script.
target.<your_date_field_column_name> = 'NULL';
Regards,
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2018 11:27 AM
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?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2018 11:37 AM
Another option is to do like below
target.u_ad_account_expires = '';
This should not cause any error
Regards,
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2018 11:55 AM
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);