Docs Menu
User Guide / Control Structures / Map

The MAP Statement

The MAP statement is a commonly used feature on the platform that allows various operations within the Syncloop workspace. This documentation aims to provide a comprehensive understanding of the MAP statement and its functionalities.

Creating a MAP Statement

To create a MAP statement, right-click on the Control Flow section and select MAP from the context menu strip. The MAP statement will be generated in the Control Flow section of the Syncloop workspace.

A MAP statement is used in the Syncloop workspace for conducting the following operations.

  1. Creating a new variable/element and assigning a value to it.

  2. If the variable is already created, you can drop it in the next step.

  3. Mapping of two variables.

  4. Customise Mapping using Custom Mapping Configuration feature

MAP Statement

Creating a new variable under MAP step

To create a new variable, you can utilize the MAP statement.

Simply click on MAP to access the input and output section of the MAP statement.

In the response section, right-click and choose the option to create a new variable. Select the data type to create any variable type within the Output section.

MAP Statement

MAP Statement

Operations Performed on Variables

The tools available in the Input and Output sections of the workspace are shown below:

MAP Statement

To assign a value to the string variable test click on the pencil icon in the toolbar and assign a value Blank to it.

MAP Statement

Let's discuss all the options provided in the Set Dialog:

MAP Statement

Once the value is assigned to the variable a pencil sign is visible with the variable name under that map.

MAP Statement

Multiple MAP Statements

In addition to creating a single MAP statement, it is also possible to create multiple MAP statements and access variables that were created in previous MAPs. It is even possible to drop variables that have already been created in earlier MAP statements.

To demonstrate this feature, let's consider an example where we have multiple MAP statements. When we select a different MAP statement that was recently created, the pencil icon associated with the variable is no longer visible. Additionally, we notice that the variable "test" is repeated in both the request and response sections of this subsequent MAPs.

This indicates that the variable is not created within the current MAP statement. Each MAP statement represents a distinct step in the service. If we want to eliminate the need for the variable in subsequent steps, we can choose to drop it.

To drop the variable "test" in the above example, select the variable and click on the drop tool located in the response section.

MAP Statement

Once a variable is dropped, it cannot be referenced in any subsequent MAP statements.

Now, when we create a new MAP statement, we observe that the variable "test" is not repeated in either the request or response sections. This is because it was dropped in the previous step, effectively removing it from the service flow.

Mapping two Variables

This step is crucial for propagating variable values within the platform. To create a new variable called test2, follow the instructions below:

  1. Locate the second MAP statement.

  2. In the Request section, find the variable named test.

  3. Click and drag the test variable to map it with the test2 variable in the Response section.

By performing this mapping, the value of the test variable will be assigned to the newly created string variable test2.

MAP Statement

The mapping operation can be represented programmatically as follows:

test2 = test

Custom Mapping Configuration

The Custom Mapping Configuration option is used to customize the mapping between two variables. This feature allows for the modification of existing mappings according to specific requirements. To illustrate this, let's create an example using the API Custom Mapping.

Follow the steps below to implement Custom Mapping Configuration:

  1. Create a MAP statement in the workspace.

  2. In the Response Section, create an integer variable called "intA" and assign the value of 10 to intA.

  3. Create another MAP in the workspace and create an integer variable named "intB" in the output section.

  4. Create an integer variable "intB" as the output parameter.

  5. Click on another map and map "intA" and "intB" as shown in the video.

At this point, we have two variables, "intA" and "intB", which will be involved in this mapping process.

To enable custom mapping, the desired mapping line needs to be selected. Click on either end of the line until it turns red, indicating that it has been selected.

Once the line is selected, locate and click the "Custom Mapping Configuration" tool in the toolbar. This action will open a dialog box specifically for custom mapping configuration.

MAP Statement

The various options provided in the dialog are explained in the table below:

MAP Statement

To configure custom mapping, follow these steps:

  1. Select the method as "custom" and write the code in the function(val) section.
    function(val) {
        val = val + 10;
        return val;
         }
        
  2. By default, the intA variable is assigned a value of 10. When the mapping is executed, the value of intA will pass through the val variable. Therefore, intB will be assigned a value of 20, as val = 10 + 10 = 20.

  3. Execute the Service Endpoint on the browser to see the result.

MAP Statement

Result:

MAP Statement

To modify the service and add an input value to the variable intA, follow these steps:

  1. Create an integer input parameter named intInput.

  2. Inside the function, write the code as shown in the figure.

val = val + $(intinput);
return val;

After modifying save the service and test it using the Postman application.

For example, if the input value is 200, the mapping function will add the value of 10 to the input value, resulting in intB = 210.

Please note that if the condition option of Custom Mapping Configuration is set to false, the mapping will not take place, and it will result in an error.

MAP Statement

To implement the Custom Mapping Configuration feature successfully, ensure that the condition remains true.