We recommend using Lookup Tables for code translation instead of dataMap Functions.

dataMap translates a string or field from the input into a string or field in the output using a translation table stored in a text file.

There are two dataMap functions:

  • One for translating a field in-place.
  • One to translate a passed in string.

The dataMap function always uses the first column to lookup the input, and the second column to extract the output. The dataMapColumns function has extra arguments for the column to lookup the input, and the column to extract the output.

Transform an input string:

output = dataMap(inputString, file)
output = dataMap(inputString, file, separator)
output = dataMap(inputString, file, separator, default)
output = dataMapColumns(inputString, inputColumn, outputColumn, file)
output = dataMapColumns(inputString, inputColumn, outputColumn, file, separator)
output = dataMapColumns(inputString, inputColumn, outputColumn, file, separator, default)

Transform a field in place:

message.dataMap(fieldPath, file)
message.dataMap(fieldPath, file, separator)
message.dataMap(fieldPath, file, separator, default)
message.dataMapColumns(fieldPath, inputColumn, outputColumn, file)
message.dataMapColumns(fieldPath, inputColumn, outputColumn, file, separator)
message.dataMapColumns(fieldPath, inputColumn, outputColumn, file, separator, default)

For example, if a JavaScript filter needs to translate city abbreviations (AKL, WGTN, CHCH) into the city names (Auckland, Wellington, Christchurch), the input message could be:

MSH|^~\&|||||||ZZZ|||
ZZZ|AKL| 

The output message would be:

MSH|^~\&|||||||ZZZ|||
ZZZ|Auckland|

The first field of the ZZZ segment has been translated from AKL to Auckland.

If C:\city-translations.txt contains the translation table as below:

AKL,Auckland,City of Sails
WGTN,Wellington,Capital City
CHCH,Christchurch,Garden City
%default%,unknown,unknown

The following JavaScript could use the translation file to convert the ZZZ/City field in-place from a city abbreviation to a city name:

for (var i = 0; i < input.length; i++) {
    var next = output.append(input[i]);

    next.dataMap("ZZZ/City", "C:\\city-translation.txt") ;
}

To store the output of a dataMap() in a property, instead of changing a field in-place, use the other form of dataMap:

for (var i = 0; i < input.length; i++) {
    var next = output.append(input[i]);

    var cityAbbreviation = input[i].getField("ZZZ/City");
    var cityName =  dataMap(cityAbbreviation, "C:\\city-translation.txt") ;
    next.setProperty("city", cityName);
}

To store the city's slogan in a property, the dataMapColumns function can be used:

for (var i = 0; i < input.length; i++) {
    var next = output.append(input[i]);

    var cityAbbreviation = input[i].getField("ZZZ/City");
    var citySlogan = dataMapColumns(cityAbbreviation, 0, 2, "C:\\city-translation.txt");
    next.setProperty("citySlogan", citySlogan);
}