Adding a JavaScript function to create a map from CSV data

You can use these JavaScript functions to convert any CSV data from a variable or file into a map. This can be used to convert the dbexport output into a map or to convert a vendor CSV file into a map.

To get started, open Infor Process Designer and either open an existing Infor Process File or create a new one. Then, select or add a node, such as an Assign node, and open the Variable Expressions Builder to specify the variable value.

Here is an example of using JavaScript functions. This is the existing method to convert Employee dbexport output into a map.
var lines = String(dbexport).split(/\r\n|\n/).filter(Boolean);
var names = Object.create(null);
var header  = lines.shift();

var footer = lines.pop();

lines.forEach(function(line) {
    var [hrorg,employee,fullname]= line.split(",");
    var key = hrorg +"|"+employee;
    names[key] = {
        FullName: fullname
		
    }
});

lines = [];
However, there are new JavaScript functions available, and this is the new method to convert the Employee dbexport into a map: map.createMapFromCSV(data(file/variable), readFromFileBoolean, mapName, keyColumns(Pipe separated), hasHeaderBoolean, hasFooterBoolean, nonKeyColumns(Pipe separated))
Parameter Description
data(file/variable) CSV data can be converted into a map. The data can either be in a flow variable or in a file (PfiFileStorage in MT).

To use a literal, hardcoded file name, enclose it in double quotes, for example, “employee.csv”. Otherwise, it will be treated as a variable and resolved into a value for the file name.

readFromFileBoolean True if the data is in a file, false if the data is in a variable.
mapName Name of the map: this must be a unique map name in the flow if multiple maps are being created. Use double quotes for a hardcoded map name.

This map name is required to retrieve the data from the map later in the flow.

keyColumns(Pipe separated) Columns from the CSV data to be used as keys in the map. Use a pipe (|) to combine multiple columns into a single key. Use double quotes for hardcoded key names, for example, “Employee|HROrganization”.

Headers for the columns must be used if hasHeaderBoolean is set to true; otherwise, use column numbers, for example, “1|2”.

hasHeaderBoolean True if the CSV data has headers; otherwise, false. This determines what to use as key columns. Even if the CSV data has headers, set this to false if you prefer to use column numbers as keys.
hasFooterBoolean True if the CSV data has a footer at the end; otherwise, false. If this is set to true but there is no footer, the last row in the CSV data will be skipped.
nonKeyColumns(Pipe separated) Columns from the CSV data to be turned into values in the map. Even if there are 10 columns in the CSV data that are not key columns, you can specify only the 2 columns you need as values in the map. Use a pipe (|) to combine multiple columns into a single value. Use double quotes for hardcoded column names, for example, “Job|Description”.

Headers for the columns must be used if hasHeaderBoolean is set to true; otherwise, use column numbers, for example, “7|9”. If all non-key columns should be turned into value fields in the map, simply specify “all”.

Here are specific examples for using the new JavaScript functions to convert any CSV data from a variable or file into a map.
map.createMapFromCSV(dbexport, false, "employeemap", "Employee|HROrganization", true, true, "all")
map.createMapFromCSV(“employee.csv”, true, "employeemap", "Employee|HROrganization", true, true, "Job|Description")
map.createMapFromCSV(“employee.csv”, true, "employeemap", "1|2", false, true, "7|8")
Use this function to retrieve or access the value fields from the map created using the JavaScript functions mentioned above: map.get(mapName, key, valueField, returnEmptyForNoValueBoolean)
Parameter Description
mapName The name of the map created earlier that contains the values you need to retrieve. Ensure you use the correct map name if multiple maps have been created.
key The key value used to retrieve the value field. If multiple key columns were used to create the map, the order must match.

For example, if “Employee|HROrganization” was used as the key while creating the map, and 111 and 222 are values for Employee and HROrganization respectively in the CSV data, then the key value must be “111|222”. Conversely, if “HROrganization|Employee” was used as the key, the key value must be “222|111”.

valueField The column name or number of the non-key column that you want to retrieve. If a column name was used to create the map, you must use the same name. Otherwise, use the column number.

For example, use “Job” or “7” if you need the Job column, and “Description” or “8” if you need the Description column.

returnEmptyForNoValueBoolean True if you want to return an empty value when the key is not found in the map; false if it should be treated as an error and return undefined.

Setting this to false and not finding the key in the map will result in an ErrorMessage in the work unit, which could slow down the process, although the work unit itself will not fail.

Here are specific examples to retrieve or access the value fields from the map created previously.
map.get(“employeemap”, “111|222”, “Job”, true)
map.get(“employeemap”, “111|222”, “Description”, true)
map.get(“employeemap”, “111|222”, “7”, false)