Update target with a null value if the source is null from transform map

Community Alums
Not applicable

Update target with a null value if the source is null from transform map with out using 'Copy Empty Fields'

 

I have used below script but it is not working, could I get some help here please

answer = (function transformEntry(source,target) {

//var gdt = new GlideDateTime(source.u_last_day);
//return gdt.getValue();
//if (source.u_last_day == '') {
if (source.u_last_day.nil()){
target.u_last_day == '';
}

})(source);

22 REPLIES 22

Community Alums
Not applicable

The field I'm trying is not mandatory, I see there's is a data policy error from Import logs. It says User ID should be populated, but thats always populated and mandatory not sure about the error.

 

I tried the script from below post but that isn't working

 Import AD date fields to users table: Unable to format undefined using format string yyyy-MM-dd HH:m...

 

LDAP Transform Dates - ServiceNow Community

jaheerhattiwale
Mega Sage
Mega Sage

@Community Alums Write below code

answer = (function transformEntry(source) {

if (!source.u_last_day) {
return "";
}

})(source);

 

And set the target field as Last day in field marked in image below

jaheerhattiwale_0-1676520446268.png

 

 

Please mark as correct answer if this solves your issue.

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

Community Alums
Not applicable

Sorry, this didn't work

Mahesh Baraskar
Mega Guru

@Community Alums   Hello, 

 

Can you try below code:

 

answer = (function transformEntry(source,target) {

if (source.u_last_day.nil()){

var null_date = new Date(0);

target.u_last_day = null_date

//or you can check this also   target.setValue('u_last_day', null_date);
}

})(source);

 

 

Community Alums
Not applicable

@Mahesh Baraskar 

Thanks for the response.

It did not work, I need to copy values when there is some data in it and copy empty value when it is blank. I believe this script works only for null values.