> ## Documentation Index
> Fetch the complete documentation index at: https://docs.refold.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Field Mapping (Map V2)

Field mapping comes as a crucial feature when you want your users to map their application platform's fields to your fields in order to make sure the correct data is being
synced from the platform and vice versa.

<img height="200" src="https://mintcdn.com/cobalt-55/qu02QklkWCst59D2/images/Config/mapping.png?fit=max&auto=format&n=qu02QklkWCst59D2&q=85&s=9d0d80f646583a7841f8d87ca9d08752" alt="Mapping fields" data-path="images/Config/mapping.png" />

Such mappings can be either **static** or **dynamic** depending upon your use case. In either case, you'd have to create a `Map V2` type dataslot setting in your application or workflow
configuration settings in Refold.

A `Map V2` type dataslot is a type of user config that allows your users to define a mapping between an object in **your application (Source Column)** and an object in their **connected integration account (Destination Column)**.

### Mapping Setup using Map V2

Based on the use-case whether you want to create mapping on an application or a workflow level, navigate to the **Config Portal** of the app in Refold.

Follow these steps to setup a Map V2 Config

<Steps>
  <Step title="Create Config field">
    In the Config Portal, click on `+ Add Field`, provide a name and select the `Type` as `Map V2` and click on `Add field`.

    <img height="200" src="https://mintcdn.com/cobalt-55/qu02QklkWCst59D2/images/Config/mapping-create.png?fit=max&auto=format&n=qu02QklkWCst59D2&q=85&s=519633620f6e43aef4d4ad47837b5de0" alt="Create Mapping" data-path="images/Config/mapping-create.png" />
  </Step>

  <Step title="Configure Source fields">
    Click on edit for the mapping created and let's configure the Source column.

    Provide a **Name** for the column, select `Type` as **Select** and then add the options.

    For mapping, you can either provide [Static](/build/connectors/config/mapping#static-mapping) or [Dynamic](/build/connectors/config/mapping#dynamic-mapping) mapping based on your usecase.

    For Static mapping, simply add the fields as options and if you want to add Dynamic Mapping here, then `Use DataSource` and select the workflow from which you are fetching fields.

    <img height="200" src="https://mintcdn.com/cobalt-55/qu02QklkWCst59D2/images/Config/static-mapping.png?fit=max&auto=format&n=qu02QklkWCst59D2&q=85&s=c1172466f500d7759800a9b237cf85ff" alt="Static Mapping" data-path="images/Config/static-mapping.png" />
  </Step>

  <Step title="Configure Destination fields">
    In Destination, you usually configure the fields from third party application which the user will map with the Source fields.

    Provide **Name** for Destination and select the object fields which you want from `Type`.

    <img height="200" src="https://mintcdn.com/cobalt-55/qu02QklkWCst59D2/images/Config/destination-mapping.png?fit=max&auto=format&n=qu02QklkWCst59D2&q=85&s=54654c62660fdce0a1d5e0d7593ba426" alt="Destination fields configure in Mapping" data-path="images/Config/destination-mapping.png" />

    <Tip>
      If a particular object's fields are not present as Type, you can create a DataSource workflow in which you fetch the fields from third party application and then use that Data Source workflow here.
    </Tip>
  </Step>

  <Step title="Save the mapping">
    Once both Source and Destination column are configured, click on `Save field` and the mapping will be available to all your Linked Accounts.
  </Step>
</Steps>

### Static mapping

Static mapping essentially means that you have a set of pre-defined fields for which you want your users to map the respective application fields. User can create the required labels by choosing `Select` as the type and entering the `Options` under the **Source** column.

<img height="200" src="https://mintcdn.com/cobalt-55/qu02QklkWCst59D2/images/Config/static-mapping.png?fit=max&auto=format&n=qu02QklkWCst59D2&q=85&s=c1172466f500d7759800a9b237cf85ff" alt="Static Mapping of fields" data-path="images/Config/static-mapping.png" />

In the **Destination** column, under `Type`, choose the object properties which you want the user to map.

<Tip>
  If an object fields are not present under Type, you can check the `Use Data Source` option and get the fields using Data Source. Learn more about DataSource [here](https://docs.gocobalt.io/build/connectors/config/datasourc).
</Tip>

On setting the static map type dataslot, the config returns the application fields along with the created labels. These labels consist of the name provided by you and system generated static value. This `value` is mapped to the application platform fields.

```JavaScript theme={null}
"fields": [
    {
      "required": false,
      "id": "65a0ee61b542ff4a62fe68b9",
      "name": "Map Deal Fields",
      "field_type": "map",
      "options": [
        {
          "name": "HubSpot Campaign",
          "value": "hs_campaign"
        },
        {
          "name": "Closed Won Date (Internal)",
          "value": "hs_closed_won_date"
        },
        {
          "name": "Global Term Line Item Discount Percentage",
          "value": "hs_line_item_global_term_hs_discount_percentage"
        },
      ...
      ],
      "labels": [
        {
          "name": "Name",
          "value": "65a0ef4db542ff4a62fe6a0c"
        },
        {
          "name": "Amount",
          "value": "65a0ef4db542ff4a62fe6a0d"
        },
        {
          "name": "Request ID",
          "value": "65a0ef4db542ff4a62fe6a0e"
        }
      ],
      "multiple": false,
      "hidden": false
    }
]
```

Next time when you'd like to update the value of the mapped field with some data, send the data against
the system generated `value`.

### Dynamic mapping

Scenarios where the fields cannot be pre-defined for mapping and changes dynamically cannot be mapped using static mapping. For this Refold provides a feature to load your fields dynamically using [DataSource](https://docs.gocobalt.io/build/connectors/config/datasource).

To do so, instead of creating the options in the config specific to a workflow or the application, simply toggle the `Use Data Source` option under **Source** column and select the workflow from which you will fetch fields dynamically during run time.

<img height="200" src="https://mintcdn.com/cobalt-55/qu02QklkWCst59D2/images/Config/dynamic-mapping.png?fit=max&auto=format&n=qu02QklkWCst59D2&q=85&s=2f7d96915c80d645eadb74d104523279" alt="Dynamic Mapping of fields" data-path="images/Config/dynamic-mapping.png" />

```JavaScript theme={null}
cobalt.config({
  slug: "hubspot",
  config_id: "OPTIONAL_ID_FOR_THIS_CONFIG",
  labels: {
    "Contact Fields":[
        {
            "name": "First Name",
            "value": "first_name"
        },
        {
            "name": "Registration id",
            "value": "r_t353553gq12"
        }
    ]
  }
})
```

<Info>
  Note here that unlike static mapping, the source field values here are not system generated but defined by the user in the DataSource workflow.
</Info>

### Getting map-type config from frontend SDK

Use the config() function to get the config of a particular app.

`cobalt.config('mailerlite','configid');`

Let's look at a sample response of map-type dataslot.

As you can see, the previously empty `labels` array now has the options configured above on the platform - 'Name' and 'Email'.

```JavaScript theme={null}
{
    "application_data_slots": [
        {
            "required": true,
            "id": "645df2f8e77af6ed8d02f32f",
            "name": "Map Mailerlite Fields",
            "has_dynamic_map_fields": false,
            "field_type": "map",
            "options": [
                {
                    "name": "City",
                    "value": "city"
                },
                {
                    "name": "Company",
                    "value": "company"
                },
                {
                    "name": "Country",
                    "value": "country"
                },
                {
                    "name": "Last name",
                    "value": "last_name"
                },
                {
                    "name": "Name",
                    "value": "name"
                },
                {
                    "name": "Phone",
                    "value": "phone"
                },
                {
                    "name": "Secondary_Email",
                    "value": "secondary_email"
                },
                {
                    "name": "Zip",
                    "value": "z_i_p"
                }
            ],
            "dynamic_slot_identifier": "dynamic:mailerlite:1",
            "labels": [
                {
                    "name": "Name",
                    "value": "645df30fe77af6ed8d02f338"
                },
                {
                    "name": "Email",
                    "value": "645df30fe77af6ed8d02f339"
                }
            ]
        }
    ],
    "workflows": [],
    "config_id": "1234"
}
```

### Updating value of map-type config

Use the updateConfig() function to save the selected value. In this case an object with respective labels and their values will be needed to pass.

```JavaScript theme={null}
cobalt.updateConfig('pipedrive','1234',{
    "config_id": "1234",
    "application_data_slots": {
        "645df2f8e77af6ed8d02f32f": {
            "645df30fe77af6ed8d02f339": "secondary_email",
            "645df30fe77af6ed8d02f338": "name"
            }
        /*[response.application_data_slots[0].id] : {
            [response.application_data_slots[0].labels[0].value]: response.application_data_slots[0].options[4].value
            [response.application_data_slots[0].labels[1].value]: response.application_data_slots[0].options[6].value
          } 
        */
    },
    "workflows": []
});
```

It will return the same response as config() functions with updates in the changed value. You will notice that the value is now added in the object.

```JavaScript theme={null}
{
    "application_data_slots": [
        {
            "required": true,
            "id": "645df2f8e77af6ed8d02f32f",
            "name": "Map Mailerlite Fields",
            "has_dynamic_map_fields": false,
            "field_type": "map",
            "options": [
                {
                    "name": "City",
                    "value": "city"
                },
                {
                    "name": "Company",
                    "value": "company"
                },
                {
                    "name": "Country",
                    "value": "country"
                },
                {
                    "name": "Last name",
                    "value": "last_name"
                },
                {
                    "name": "Name",
                    "value": "name"
                },
                {
                    "name": "Phone",
                    "value": "phone"
                },
                {
                    "name": "Secondary_Email",
                    "value": "secondary_email"
                }
            ],
            "dynamic_slot_identifier": "dynamic:mailerlite:1",
            "labels": [
                {
                    "name": "Name",
                    "value": "645df30fe77af6ed8d02f338"
                },
                {
                    "name": "Email",
                    "value": "645df30fe77af6ed8d02f339"
                }
            ],
            "value": {
                "645df30fe77af6ed8d02f339": "secondary_email",
                "645df30fe77af6ed8d02f338": "name"
            }
        }
    ],
    "workflows": [],
    "config_id": "1234"
}
```
