Docs Menu
User Guide / Control Structures / Map

The MAP Statement

This is one of the most frequently used statements on the platform. A MAP statement is created by right-clicking on the control flow section and selecting MAP from the context menu strip. A map is created in the control flow section of the Syncloop workspace.

MAP Statement

A map statement will be created in the workspace.

MAP Statement

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

  1. Creating a new variable and assigning a value to it.
  2. If the variable is already created, we can drop it in the next step
  3. It is used to map two variables.
  4. Custom Configuration Mapping
1. Creating a new variable

The MAP statement can be used to create a new variable.

After creating a new MAP, click on it and the request and response sections of the map statement will be visible.

MAP Statement

Right Click on the Response Section and create a new variable in the response section and select String. A string variable will be created in the Response Section.

MAP Statement

The string variable can be renamed by right-clicking on it.

MAP Statement

Operations Performed on Variables

The tools available in the Request and Response sections of the workspace are shown below:

Tool Name Logo Operation
Maximize MAP Statement It maximizes the Request and Response Window
Custom Mapping Configuration MAP Statement Configures the custom mapping
Drop an Element MAP Statement Renders element/variable unusable for the current step
Initialize an Element MAP Statement Assigns value or expression to the variables
Delete Mapping Value MAP Statement Deletes the configuration mapping, drop function
Refresh MAP Statement Refreshes the variable/element.

Rename the variable from String to test right click on the variable and select rename. 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 us discuss all the options provided in the Set Dialog

Option Name Operation
None Using this option, a constant value can be assigned to the variable
Evaluate Expression An expression can be given
Evaluate Local Package variables Here the value can be picked from the local configuration
Evaluate Package Configuration Variables Here the value can be picked from the Package Configuration
Evaluate Global Configuration Variables Here the value can be picked from the Global Configuration

Video Links can also be provided here that have been already created for these options.

Once the value is assigned to the variable a pencil sign is visible with the variable name

MAP Statement

2) Multiple MAP Statements

We can also create multiple MAP statements and access variables created in the previous statement. We can also drop the variable that has been already created in the previous MAP statements.

To implement that let us create more MAP statements in the above example. Once we select the other map that we have recently created the pencil sign with the variable is not visible. We also observe that the variable test is repeated in both request and response sections in this next map.

MAP Statement

This provides the information that the variable is not created in the current MAP statement. Every MAP statement adds a new step in the service. If we wish that the variable is not needed in the following steps, we can also drop the variable.

To drop the variable test select the variable and click on the drop tool in the response section.

MAP Statement

Once the variable is dropped it cannot be repeated in the next MAP.

Now creating a new map, we observe that the variable test is not repeated in both request and response sections it has been dropped in the previous step.

MAP Statement

3) Mapping two Variables

This is an important step in the variable value propagation on the platform. Let us create a new variable test2 in the second MAP statement. Now click on variable test in the Request section and drag it to map with the test2 variable in the Response Section.

MAP Statement

Here the select MAP statement is the second one. The mapping arrow direction also tells us that the value is also flowing in this direction. Here variable test value will be assigned to the newly created string variable test2.

This mapping operation is programmatically interpreted as

tes2 = test

4) Custom Mapping Configuration

This option is used when we need to customize the existing mapping between two variables. To illustrate it let us create one API CustomMapping. We want to add value of 10 to the source variable and reflect that value in the destination variable.

Create a MAP statement in the workspace
Create one integer variable intA in the Response Section.
Create another map in the workspace and create one more variable intB
Create one intB variable as an output Parameter
Click on another map and map intA and intB as shown:

MAP Statement

Here we have two variables intA and IntB that perform on this mapping line.

Before implementing custom mapping, we need to select this mapping line. To select this mapping line, click on any of the line's ends so that the line turns red.

MAP Statement

Once the line is red., click on the Custom Mapping Configuration tool in the toolbar, A custom mapping configuration dialog will be displayed

MAP Statement

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

Option Name Description
Path From Source Variable
Path To Designation Variable
Method Some default function methods are provided including custom methods. If the method is selected as the custom then we need to explicitly specify the code in the function.
Condition To specify conditions on mapping. This condition has to remain true and then only the mapping will take place.
function (Val) This is the mapping function that will be executed when mapping will be performed. For every selection of method, the function code will change accordingly. On the Custom method, the developer can specify his own configuration mapping code.

Let us take an example of custom configuration mapping.

Select Method as custom and write the code in the function(val) section

function(val){
val = val + 10;
Return val;
}

We have already assigned a value of 10 to intA.
When this mapping will be executed the intA value will pass through val variable.
Therefore, the intB will be assigned a value of 20 i.e. val = 10 + 10 = 20.
Now executing the endpoint on the browser, we get

MAP Statement

Now let us try to modify the above service so that an input value is added to the variable intA For that

Create an integer input value as an input parameter and name it intInput. Now write the code in the function as shown in the figure and click on the OK button.

MAP Statement

Now save the project and test the code postman application.

MAP Statement

In this case, the input value was 200. When the mapping was done the value of 10 was added to the input value and this assigned intB = 210.

if the condition option of Custom Configuration Mapping is made false then the mapping will not take place and it will result in an error in this case.

MAP Statement

There to implement Custom Configuration Mapping feature the condition has to remain true.