Generic Mapping
The generic mapping capability lets you map keys to values, with the mapping stored in a high-performance data store. Generic mapping supports large datasets, with high performance for lookup.
For example, you can map SKUs from a backend system to Salesforce B2C Commerce SKUs on-the-fly using B2C Commerce script, so that interaction with the backend system is transparent and doesn't require adding B2C Commerce SKUs to the third-party system.
By using generic mapping, B2C Commerce customers can access in-memory key value pairs that complement product data in the database.
Steps to Use Generic Mapping
Generally, follow these steps to use Generic Mapping:
- Create the mapping.
- Upload the mapping to the B2C Commerce server
- Create a job that uses the ImportKeyValueMapping job step.
- Use B2C Commerce script to read values from the mapping.
Create the Mapping
Create a .csv (comma-separated value) file to store the mapping. Follow these guidelines:
- Put each key and associated value on one line
- Separate keys and values with a comma.
- Ensure that .csv files for import into maps have a fixed number of entries per row.
The format for each line of the .csv file is:
(<key>[,<key2>,…],<value1>[,<value2>,<value3>,...])
The first row of the .csv file defines the property names for the key value entries. The key value entries start in row 2. The generic mapping contains one fewer entry than the number of rows in the .csv file. When you call MappingMgr.get(mapping, key), you get a new map with the property names as keys.If malformed records are encountered, the import fails with an exception that is logged.
Before importing a mapping, upload it to a place accessible by the application server, for example by using a Business Manager upload page or FTP. Mappings must be explicitly imported on each instance. Mappings are global (not site-specific).
Mapping files are limited to 20 MB, which is equivalent to 1M records of 20 bytes and a maximum of 20 mappings.
Upload the Mapping
Uploading the mapping makes it accessible.
To upload the .csv file using Business Manager:
- Select .
- Under Import & Export Files, click Upload and select the .csv file.
Alternatively, you can upload the .csv file to the Impex directory using WebDAV or httpClient.
Create a Job
Create a job that uses the ImportKeyValueMapping job step, which transforms .csv files into in-memory key-value mapping and notifies all application servers in a cluster that there is a new mapping. The ImportKeyValueMapping job step supports Replace, Delete, and Merge import modes.
Read Values from the Mapping
The dw.util.MappingMgr class, with the following methods, enables you to access mapping data.
- get(String mappingName, MappingKey key): gets a collection of string values of a mapping by name and multiple key values
- getFirst(String mappingName, MappingKey key) gets the first element of a collection of string values of a mapping by name and key
- getMappingNames(): gets a collection of string values for a specific mapping and a mapping key
- keyIterator(String mappingName): key iterator over known mapping keys by mapping name