MAPPING Component

Using the MAPPING component.

The MAPPING component enables you to add a component to service flow that outputs a custom response in JSON form. You can also run JavaScript logic in response.

233

Mapping component.

Let's run through a quick example.

  1. Let's say that API Express service has two query parameter called: temperature (number) and units (string).
  2. Drag and drop the MAPPING component on to the service flow.
  3. In MAPPING component properties the first text area is where you define the response of this component. It can be any valid JSON response. In our example, enter the following:
{"currentTemperature":"", "temperatureUnit":""}

This means that the MAPPING component output will be in that JSON format.

  1. Click on the Generate mapping button.
  2. Click the Expand all links on both sides of the mapping editor. On the left-hand side, you should see the two query parameters (Params > Query) and on the right-hand side, you should see the MAPPING component output that you just defined.
  3. Using drag and drop create the following mapping:
  • temperature to currentTemperature
  • units to temperatureUnit
  1. Click the Save & Replace button. This will generate the mapping code and display it in MAPPING component properties.

With the help of the MAPPING component, you created a component that outputs a custom JSON result.

911

Mapping component editor.

In addition to mapping you can also write logic in JavaScript. For example, let's say you want to increase the temperature by 5 degrees. You can update the generated mapping like this:

var result = AE.EntityAPI("result", AE_MODEL);
result.currentTemperature = PARAMS.QUERY.temperature + 5;
result.temperatureUnit = PARAMS.QUERY.units;

📘

Custom code

When you write custom code, the visual mapping editor will not be updated.