Transform maps - how to set *some* target fields to false when the source is null

tanuja_g
Tera Contributor

Basic question, but has defeated me so far

Importing data (from CSV) and transforming to scoped application custom table

I have fields in the imported data that map to 5 choice fields with 2choices

For these five fields only - when the source is TRUE I need the target field set to True, if the source is NULL / FALSE I need the target field to be set to False.  Any other source fields that are null are not to overwrite the target

I cannot work out how to only do this for some fields

 

Any thoughts on how to proceed?

4 REPLIES 4

Suyog Aptikar
Giga Guru

How you did it? Are you trying to achieve this via script if so can you provide more details of it.

I didn't used the script. Can someone please help with how to script?

On high level this is something you can try, I will try it at my end and add here, meantime you can use script of field level mapping

if(source.field_name == true){   //replace field name with your source field mapping
return true;
}
else if(source.field_name == false || source.field_name == '')
{
return true;
}

SuyogAptikar_0-1697530089403.png

 

Ankur Bawiskar
Tera Patron

@tanuja_g 

you can use onBefore transform script for this

Don't have field map for these 5 fields which are choices as we will be using onBefore script for that

Something like this

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

	// Add your code here
	if(source.u_field == 'TRUE'){
		target.field1 = true;
		target.field2 = true;
		target.field3 = true;
		target.field4 = true;
		target.field5 = true;		
	}
	else if(source.u_field == 'FALSE'){
		target.field1 = false;
		target.field2 = false;
		target.field3 = false;
		target.field4 = false;
		target.field5 = false;		
	}

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

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