Field Map Scripting-Transform Map

Lakshmi Prasann
Giga Expert

Hello Experts,
We have a requirement regarding a field named "State/Province" in location table (cmn_location).While we do data migration from source to target(ServiceNow),Source system is maintaining two different fields,one is State and another one is Province.But in ServiceNow,we are maintaining  a single field which is "State".we have to populate both the values of fields( state and province)of source to a single field "State" in ServiceNow using Source script in field map.
Need your suggestions.
Thanks in advance

3 REPLIES 3

Abhinay1
Giga Expert

Hello Lakshmi,

You can write a new onBefore Transform script.

1) Open Table Transform Maps table 'sys_transform_map.LIST' and open the record

2) Go to Transform Scripts, and click New

3) Create a onBefore script and in the script section write below script

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

    // Add your code here
u_state = field_name_containing_province_val + ', ' + field_name_containing_state_val;

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

find_real_file.png

 

Hope this will help you.

Regards,

Abhinay

emir
ServiceNow Employee
ServiceNow Employee

if I understand you want to use state (USA for example), and if state is empty then use province (like Canada).

Use a ternary operator, and map the resulting value to the target field

SunilKumar_P
Giga Sage

Hi @Lakshmi Prasann, You can achieve this with either field map (make sure to check use source script) or a transform map script.

 

Source Script:

var concatState = source.u_state.toString() + ", " + source.u_province.toString();
return concatState;

SunilKumar_P_0-1707906022663.png

 

Transform Script:

var concatState = source.u_state.toString() + ", " + source.u_province.toString();
target.state = concatState;

 

SunilKumar_P_1-1707906088002.png

 

Regards,

Sunil