Skip to main content
All CollectionsAdvanced Topics
Advanced Import mapping & transformations
Advanced Import mapping & transformations

When data should be modified during import or trigger actions like categorization or user group assignment, use import mapping

Michael Fatica avatar
Written by Michael Fatica
Updated over a week ago

This article describes features available to Enterprise users only.

Find Import mappings under Tools > Import Mapping, the following screen lists any existing mappings. To create a new mapping, click New.

Category Mapping

In some cases, users would like rows to be added to a category if a field contains a certain value. This mapping type is Category.

For example, if the FavoriteColor column contains the value 'red', assign the row to the category with ID 25, if the FavoriteColor column contains the value 'blue', assign the row to the category with ID 26.

Wildcards are supported in the value field. E.g. red* would match any value starting with the word red, e.g. reddit, redacted. The value gr[ae]y would match grey or gray and so forth.

When mapping a column in the incoming data that is not a field, but instead a category column, the "Field Name" must be tag1. This mapping would then only apply to categories that appeared in the first category column.

Transformation Mapping

If a value should be modified programmatically during the bulk import, a Twig template can be applied to the data. The mapping type must be set to Transformation and the transformation will be applied to the value set in the Field Name.

The template is a Twig template, which can perform simple (and not-so-simple) transformations of the incoming data.

A few examples:

Replace any dashes found in the field value with dots:

{{ template_item.value|replace({'-':'.'}) }}

Remove any values greater than 5 characters in length:

{% if template_item.value|length <= 5 %}{{template_item.value}}{% endif %}

Remove any email fields without an @ sign.

{% if '@' in template_item.value %}{{template_item.value}}{% endif %}


Concatenate two fields into the Name field

{% if template_item.data.firstname %}{{template_item.data.firstname}} {{template_item.data.lastname}}{% endif %} 

The variables in template_item.data refer to the the destination MetaLocator field names, which may differ from the column names in your data file. For example, if your import maps a column in your data file labelled "Color" to the MetaLocator field "Favorite Color", the resulting template code will reference
โ€‹

template_item.data.favoritecolor

Category Mapping with Twig Templates

When multiple fields or special logic should be applied in order to categorize a given row, a template can be provided in the Category Mapping rule in order to derive the value.

For example, consider the following logic:

if the "Favorite Color" column contains the value 'red' *AND* the IsStore column is 1, assign the row to the category "Red Store".

This presumes the importing file contains columns "Favorite Color" and IsStore.

  1. Create a category called "Red Store" under Locations > Categories, and note the ID number assigned by MetaLocator.

  2. Navigate to Tools > Import Mapping and click New

  3. Choose Category for the Mapping Type

  4. Enter 1 for the Field Value

  5. Enter the Field Name that will trigger this import mapping. The Field Name in this case can technically be any field included in the import, but we will chose "Favorite Color". IsStore is also a perfectly valid choice. Important: The Field Name is the destination MetaLocator field name, which may differ from the field name in your data file. For example, if your import maps a column in your data file labelled "Color" to the MetaLocator field "Favorite Color", the Field Name should specify Favorite Color.

  6. Enter the Category ID obtained in Step 1

  7. Provide the Transformation Template as follows:
    โ€‹

    {% if template_item.data.favoritecolor == 'Green' and template_item.data.isstore == '1' %}1{% endif %}

User Group Mapping

When importing data, you can create a mapping to automatically assign a row to a user group.

Create a new Mapping and choose UserGroupId as the Mapping Type.

For example, if the Division column in your incoming data contains the value 'retail', assign the row to the User Group with ID 1, if the Division column contains the value 'commercial', assign the row to the User Group with ID 2.

Wildcards are supported in the value field. E.g. retail* would match any value starting with the word retail, e.g. retailers, retailor. The value gr[ae]y would match grey or gray.

The first example above would require a mapping as shown:

Job Mappings

It can be useful to perform a transformation on a column that is not coming from a specific data source. This is useful when you want to apply a transformation but you do not control the fields in the data source, such as when importing from SalesForce or Google My Business.

Examples include

  1. All records coming from Google My Business should have the custom field named "Segment" set to "GMB"

  2. All records coming from SalesForce should have the Name field set to the First Name plus the Last Name with a space in between.

In the above examples the Name and Segment columns aren't coming from the data source mentioned, they are custom fields in the MetaLocator account.

These mappings are done on a per-background-job basis, and can be configured as show below.

Example 1

Example 2

Linking Mappings

Import Mappings can not be linked, or otherwise inform one-another. For example, you can not use a Transformation Mapping to modify a field value, and then create a Category Mapping based on the results of the Transformation Mapping. All mapping rules operate on the data as it appears in the import file.

Did this answer your question?