Field Map Scripting-Transform Map
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-03-2022 10:22 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-03-2022 10:28 AM
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);
Hope this will help you.
Regards,
Abhinay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-03-2022 10:54 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-14-2024 02:21 AM
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;
Transform Script:
var concatState = source.u_state.toString() + ", " + source.u_province.toString();
target.state = concatState;
Regards,
Sunil