Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Ignore a field when the value is not a serial number in a transform map

Adam Wood
Tera Contributor

Hi 

I have a issue where serial numbers are been overwritten by blank values when running a transform

e.g.

CI has serial number 'abc' 

Import Set has nothing in the serial number 

Transform runs

CI serial number is blank 

 

What is best way to Skip\Ignore the transform from overwriting the value. However, I still want the other fields to update and not to skip the full row. I don't think its an Empty field as I have the 'Copy empty fields' unticked. 

 

8 REPLIES 8

Manmohan K
Tera Sage

Hi @Adam Wood ,

 

Delete the mapping for serial number in the Transform map as shown below to stop overriding the values

 

ManmohanK_0-1685454025737.png

 

Manmohan K
Tera Sage

@Adam Wood ,

 

If you only want to avoid overriding when source is empty , you can 

 enable source script for field map on transform map and write script as follow:

 

if (JSUtil.nil(source.serial_number)) {
    ignore = true;
}

 

Refer image 

 

ManmohanK_0-1685454468649.png

 

 

Hi @Manmohan K 

 

When i do this, all the serial number are set to undefined

Ankur Bawiskar
Tera Patron
Tera Patron

@Adam Wood 

remove field map for it and use onbefore transform script

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

	// Add your code here
	if(global.JSUtil.notNil(source.u_serial_number)){
		target.serial_number = source.u_serial_number;
	}

})(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