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.

How to blank out fields depending on the value of another field via a transform map

matthew_hughes
Kilo Sage

In the below form, the question '

 

However, I'm wanting to do this in a transform map so that if a user enters 'No' in a spreadsheet for that question, but they fill in the other 5 questions without knowing it, the transform map needs to blank out those 5 questions when the import has been completed.

I was just wondering if this is possible to do.

 

 

 

 

 

 

 
2 REPLIES 2

Mahendra RC
Mega Sage

Hello Matthew,

1. You can use the script type in field mapping for those 5 field to validate if the value of your variable is Yes or No and then set the value in those 5 field:

 

field 1:

answer = (function transformEntry(source) {

    var ratesFactors = source.rates_factors;
    if (ratesFactors && ratesFactors.toLowerCase() == "yes") {
		return source.field1_name;
    } else {
        return "";
    }

})(source);

Similarly use [script] in field mapping for other 4 fields as well and use similar script to return the value.

2. Other option is to use the onBefore transform script and you can remove the field mapping for those 5 fields:

var ratesFactors = source.rates_factors;
if (ratesFactors && ratesFactors.toLowerCase() == "yes") {
target.field1_name = source.field1_name;
target.field2_name = source.field2_name;
target.field3_name = source.field3_name;
target.field4_name = source.field4_name;
target.field5_name = source.field5_name;
} else {
target.field1_name = "";
target.field2_name = "";
target.field3_name = "";
target.field4_name = "";
target.field5_name = "";
}

If my answer helped you in any way then please do mark it as helpful. If it answered your question then please mark it correct and helpful. 

Thanks

Hello @matthew.hughes@lloydsbanking 

Just wanted to check with you, if the above response answered your question. If yes, then please do close this thread/question by marking the appropriate response as correct.

Thanks