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

Kirby R
Kilo Sage

Hi @Community Alums ,

 

Change target.u_last_day == ''; to target.u_last_day = '';, basically what == does is it checks and evaluates and returns true or false, not assigning value to a variable.

 

Please mark correct if this helped your issue.

 

Community Alums
Not applicable

Hi Kirby,

 

Thanks for the response.

I tried changing to target.u_last_day = ''; but its still not working.

Mahesh Baraskar
Mega Guru

@Community Alums   Hello,

 

Please make following change at line 6:

target.u_last_day = '';

 

Please mark the answer as correct if it solves your question.  Thank you in advance.

Ankur Bawiskar
Tera Patron
Tera Patron

@Community Alums 

use onBefore transform script

I hope the target field name is correct i.e. u_last_day

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {

	// Add your code here
	if(source.u_last_day.nil())
		target.u_last_day = '';

})(source, map, log, target);

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader