Open Navigation

Data Mapper

The Data Mapper helper allows you to set up data mappings
On This Page

Overview

Sometimes when working with data in your workflows, it is necessary to set up 'mappings' for your data. Two general scenarios which would necessitate use of the Tray Data Mapper are:

  1. You are pulling data from a service and need the results to be formatted so as to update a particular field in a database with a value that is more helpful for the users of the database (e.g. 'landline call' and 'cellphone call' could both be mapped to 'phone call').

    The Data Mapper has a Map Data operation for this purpose.

  2. You wish to automatically pass data from one service to another by specifying a mapping 'table' so that e.g. the 'name' field in Service 1 is automatically mapped to the 'item' field in Service 2.

    The Data Mapper has a Map Fields operation for this purpose.

Map Data Example

map-data-workflow-2

The above example shows a manually triggered workflow which implements the following steps:

  1. Use a Script Helper to create some dummy data. In a live situation these messages would be pulled in from another connector step (Salesforce, Intercom etc.).

    data-mapper-script

    In the script box enter the following as an array of 'records':

    exports.step = function() {
    return {
    "records": [
    {"Id": "0345rgrgi6AAE", "Name": "Candidate 1", "Trial_stage": "Scheduled", "URL": "https://testcourse.com/projects/9999"},
    {"Id": "034ef3r934EwE", "Name": "Candidate 2", "Trial_stage": "Activated", "URL": "https://testcourse.com/projects/9999"},
    {"Id": "239fefuHsw9dE", "Name": "Candidate 3", "Trial_stage": "Successful", "URL": "https://testcourse.com/projects/9999"}
    ]
    }
    };
  2. Add a Loop Helper to loop through the above records one by one. Set the List as $.steps.script-1.result.records:

    loop-1

    This will loop through the array of records from the script.

  3. For the Data Mapper step set the operation to Map Data, the Value to $.steps.loop-1.value.Trial_stage and then add the Trial_stage mappings:

    data-mappings-2

    The full mappings to use are:

    From: Scheduled
    to: Trial: Scheduled
    From: Activated
    to: Trial: Activated
    From: Successful
    to: Trial: Successful
    From: Failed
    to: Trial: Failed

    So for each record that is passed to the Data Mapper, it will look for any results in the Trial_stage field and map them as above.

    Looking at the logs for a run of the Data Mapper (note that logs won't be available until you have clicked 'Run Workflow Now' after you have completed the workflow setup) will show you that the value Scheduled was passed through the mapping table and changed to Trial: Scheduled:


    data-mapper-debug

  4. Finally, the result of each loop is fed into a Google Bigquery database (you will need to authenticate the Bigquery connector with your Bigquery account and setup a dataset and table), using the Insert Rows Operation. The Project Id and Dataset Id are specified and then the result of the message is fed in:

    big-query-data-fields

    The key thing to note here is that, while the Name and Id fields take their data from the loop helper, Stage takes it from the Data Mapper using $.steps.data-mapper-1.result

  5. Once the workflow is setup, click 'Run Workflow Now'
    A successful run will then lead to your Bigquery dataset being updated.
    Logging into your Bigquery account and running a query such as SELECT * FROM trainee_trials.trainee_listing will give you a result like this:

    big-query-table-result

    Looking at the Stage field for each entry shows that our mapping has been successful!

    And clicking on the Debug tab will enable you to view the output logs of each stage of your workflow:

    data-mapper-workflow-output

Map Fields Example

Coming soon!

Was this article helpful?
Yes
No
On This Page