How to clear out the value on a form via a transform map

matthew_hughes
Kilo Sage

In my instance, I'm wanting to clear out the value of the 'IBP Tier' field of the below Application Service (cmdb_ci_service_discovered) record:

matthew_hughes_0-1779185685006.png

 

 

However, I only want users to be able to do this if they enter 'Null', 'NULL' or 'null' in the spreadsheet of the transform map as seen below:

matthew_hughes_1-1779185758970.png

 

I'm using the below field mapping:

matthew_hughes_0-1779186811243.png

 

 

 

 

However, when I run my transform, I find that it's not clearing out the 'IBP Tier' field. I was just wondering if anywhere knows what I need to do to clear the 'IBP Tier' field out.

 

6 REPLIES 6

Hi @matthew_hughes  Now that you're using Ignore, there's no need to write a script. If the choice doesn't match automatically, it won't fill the value. It will only fill if the choice value matches. Remove the script, just return the value and check.


return source.u_cbp_tier;

Ankur Bawiskar
Tera Patron

@matthew_hughes 

use onBefore transfrom script instead of field map script

// Normalise the value (handles NULL, null, Null, etc.)
var tier = (source.u_cbp_tier + '').trim().toLowerCase();

// If the value is "null", clear the target field
if (tier == 'null')
target.fieldName = '';

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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