Transforming Fields

A transformation is the result of the process of mapping fields in your element instance resources to existing fields and objects in a common resource. After you create a common resource, you will select an element instance, choose the resource containing the objects that you want to map to the common resource, and map fields to the common resource. The end result is a a transformation of the selected objects in the element instance.

Map Fields to the Common Resource

Before you can transform fields, you need to map the fields for each element instance to the common resource. The common resource fields are on the left and the element instance resource fields are on the right.

You can map fields one at a time, or you can add several fields to the common resource at once, and then map them later. These instructions describe mapping a single field at a time.

This section describes mapping to a common resource at the organization level. You must be an organization level user to map to organization level fields. For more about mapping at different levels, see Access Levels and Transformations.

To map fields:

  1. On the Common Resources > Transformations page, click Create New Transformation.

    Create New Transformation

  2. Select the Element Instance, and then select the Element Instance Resource.

    The Resources available to that Element Instance appear in the Element Instance Resources column after you select a resource. Chooser

  3. Beginning with the default field id, select a field on the right to map to id. Select Field

  4. Click Add Field next to the Organization Level Fields to add another field.

  5. Enter a name for the field, and then choose the data type if the field is something other than a string.

  6. Select the corresponding field on the right to map to the new field.

    Filtering Resources

  7. Continue adding resources until you finish, and then click Save.

  8. To map another instance, click Transformations in the breadcrumbs at the top of the page. Breadcrumbs

Tips

Use Javascript to Manage Complex Objects

You can use custom Javascript when the basic object mapping does not meet your needs. For example, you might need to break a single address object into its component parts (address.city, address.state, address.street, and address.zip).

To access the custom Javascript functionality:

Common resource functions include the parameters and functions in the following table:

Common Resources Custom JS Parameters and Functions

Parameter Description
transformedObject The transformed object, with any mappings already taking place.
originalObject The original object, with no transformations or mappings taking place on it.
fromVendor Is the transformation being executed coming back from the vendor (on an API response) ?
done The callback function needed to call at the end of your JS. Call done to terminate a given step.

Libraries

Examples

Transforming Custom Objects

If you do not see an object that you expect in the instance resources, you can still map it by entering the object name. This sometime happens for custom objects you created at the endpoint.

To map a custom object:

  1. Click Free Text Toggle.

    The list becomes a text entry field.

  2. Enter the name of the object.

    Custom Object

Removing Fields During Transformation

Cloud Elements passes through all fields in the JSON on both requests and responses. However, you can choose to remove all unmapped fields or specific fields from requests or responses.

To remove unmapped fields:

  1. On the Transformations page, click Advanced Settings.
  2. Switch Remove Unmapped Fields to on.
  3. Click Save.

To remove fields from requests or responses:

  1. On the Transformations page, click Field Settings.
  2. Switch on or off the sliders for the requests or responses.

    For example, in the following configuration, we remove the portal-id field from the response. Removed field from response

Transforming Data Types

You can transform the data types on vendor objects. In most cases, you only need to select a new data type, but for dates you also provide a mask, or date format.

To change data types:

  1. On the Transformations page, click Field Settings.
  2. Select a type from the list.
  3. If you select date, add a date format to the Date Mask.

Data Type

Setting Default Values

If no values exist for a specific field, but you do not want to remove it, you can set a default value.

To set a default value:

  1. On the Transformations page, click Field Settings.
  2. Click Default Value, and then type the value.
  3. Click Save.

Testing Your Transformations

After you set up your mapping, you can test your transformations.

To test a transformation:

  1. On the Transformations page, click Try It Out.
  2. Review the transformed response body. This is the response containing only the fields in your common resource.
  3. Click Original to see the entire response JSON payload.
  4. Test a Put or Patch by selecting the appropriate method, and then entering the JSON request.

  5. Click Run.

Adding Your Common Resource to the API Docs

You can add the common resource you create to the instances of each affected element.

To add a common resource to API docs:

  1. On the Transformations page, click Advanced Settings.
  2. Switch Add to API Docs on.
  3. Click Save.

Try it out:

  1. Go to an element instance.
  2. Hover over the instance card, and the click API Docs.
  3. Scroll to your common resource.

Working with Nested Objects

We display sub-objects in dot notation. You can also use dot notation to nest objects in your common resource. For example, you might want to create nested address fields like those shown in the example below:

Nesting Example

The JSON result of this nested object:

{
  "Address": {
    "city": "Cambridge",
    "state": "MA",
    "street":"1234567 Elm St",
    "zip":"99999"
  }
}

Access Levels and Transformations

You can map fields at different levels depending on your access. Organization level users can map at any level, while other users can map only at the instance level.

To map fields at the account level (organization level users only):

To move mapping between levels: