how to update target field with empty source value

Amit Dey1
Tera Contributor

hi, when I am updating the target field with empty value, the state is getting ignored, it is fetching empty value as null, I want if user give empty value for some field in portal, then the target field should be updated with empty values only, how to achieve it?

4 REPLIES 4

Shruti
Mega Sage
Mega Sage

Hi 

Use onBefore transform script

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

	
	if(source.FIELD_NAME.nil())
		target.FIELD_NAME = '';

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

hi, it is still not working

Ankur Bawiskar
Tera Patron
Tera Patron

@Amit Dey1 

can you share what script did you try so far and what debugging have you done?

You are talking about some field in portal but seems your response to other post talks about transform map.

It's confusing.

Can you please share your exact business requirement along with screenshot what you are talking about?

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

Animesh Das2
Mega Sage

Hi @Amit Dey1 ,

You can set the 'Copy empty fields' check box of the transform map to true as shown below.

AnimeshDas2_0-1736333213577.png

However, if you do so it will be applicable for all the fields present in field mapping. If you want this on only for some fields then for other fields you may write an onbefore script to ignore those specifically. Shown below.

 

if(source.FIELD1.nil() || source.FIELD2.nil() || source.FIELD3.nil()){
   ignore = true;
}

If this address your question, please don't forget to mark this response correct by clicking on Accept as Solution and/or Kudos.

You may mark this helpful as well if it helps you.

Thanks, 

Animesh Das