Share via


Loop and Scope Examples in map or transforms

 

Important

Microsoft Azure BizTalk Services (MABS) is being retired, and replaced with Azure Logic Apps. If you currently use MABS, then Move from BizTalk Services to Logic Appsprovides some guidance on moving your integration solutions to Logic Apps.

If you're brand new to Logic Apps, then we suggest getting started here:

Lists examples of Scope and Loop operations in BizTalk Services. Specifically:

Scope Example

ForEach Loop Example

MapEach Loop Example

Scope Example

In the following example, a Company Mapping MapEach Loop Map Operation contains the Dept Loop ForEach Loop Map Operation within its scope container. This Dept Loop ForEach Loop contains the Employee Mapping MapEach Loop within its scope container.

In this example, every time a Company and a Department name are in the input data file, this Transform generates the Company and Employee output records:

Scope is set

ForEach Loop Example

There is a Department source schema with Name, Size and Employee records. Employee has the Name and Details fields. The hierarchy formed is:

Department
   Name
   Size
   Employee
      Name
      Details

Employee{Name, Details} is mapped to Employee{Name, Details} in the target schema.

The goal is to flatten all Departments where the Size < 10. To achieve this, do the following:

To configure the Transform

  1. Add a ForEach Loop to the Transform design surface.

  2. Create a link from Department in the source schema to this ForEach Loop.

  3. Add a Logical Expression Map Operation to the Home (Page) container. Configure the expression to state: Size<10.

  4. Create a link from this Logical Expression to the ForEach Loop.

  5. Under the ForEach scope container, add a MapEach Loop to the Transform design surface.

  6. Create a link from Employee in the source schema to this MapEach Loop.

  7. Create a link from the MapEach Loop to Employee on the target schema.

  8. Create the appropriate links for the Employee Name and Employee Details fields.

With this Transform, the ForEach Loop iterates over the Department source record. For those Departments that have < 10 Employees, the MapEach Loop iterates on the Employee repeating record and populates the Employee Name and Employee Details fields in the target document.

Logical Expression Examples: BizTalk Services provides more information on the Logical Expression Map Operation.

MapEach Loop Example

There is a source schema with an Employee record. Employee has a Details record and Details has an Age field. The hierarchy formed is:

Employee
   Details
      Age

The target schema has the same structure.

The goal is to not emit records where Age > 100. To achieve this, do the following:

To configure the Transform

  1. Add a MapEach Loop to the Transform design surface.

  2. Create a link from Employee in the source schema to this MapEach Loop.

  3. Add a Logical Expression Map Operation to the Home (Page) container. Configure the expression to state: Age < 100.

  4. Create a link from this Logical Expression to the MapEach Loop.

  5. Create a link from Employee in the target schema to the MapEach Loop.

With this Transform, the MapEach Loop Map Operation creates the Employee record in the target document for those employees where Age < 100.

Logical Expression Examples: BizTalk Services provides more information on the Logical Expression Map Operation.

More Examples

More Transforms topics

Convert a BizTalk map to a BizTalk Services Transform

Use standard XSD constructs in your maps

Transforms/Maps Best Practices

Azure BizTalk Services Resources on the TechNet Wiki

See Also

Using Scope in a Loop - How To
Loop Map Operations - Usage and Examples