Forum Discussion
Hi everyone,
You may keep mapping file of source and target fields. For instance, if your create the array of mapping among source and target fields (e.g. [sourcefield, targetfield]) as follows:
{
“fields_map”: [
[
“source_field_1”,
“target_1”
],
[
“source_field_2”,
“target_2”
]
]
}
then you can use the following statement in the mapper:
$.mapKeys((value, key) => $fields_map.find(x => x[0].toLowerCase() == key.toLowerCase()) !=null ? $fields_map.find(x => x[0].toLowerCase() == key.toLowerCase())[1] : key)
If you want to have only mapped fields in the output, you can set filtering with mapper snap as follows:
$.filter((value, key) => ($fields_map.length > 0 ? $fields_map.filter(x => x[1].toLowerCase() == key.toLowerCase()).length>0 : true))
$fields_map can be generated by reading values from CSV file and by using one additional mapper snap.
Regards,
Lazo
Sorry to resurrect an old thread, but this is exactly what I want to do, have mappings in a file that is read in (or passed) and then those mappings are used…
It seems from the example that this is possible but I cant work out from the posting how to go about this, if you could expand on how to do this that would be great