Blog Post

Azure Integration Services Blog
3 MIN READ

🧩 Use Index + Direct Access to pull data across loops in Data Mapper

shahparth's avatar
shahparth
Icon for Microsoft rankMicrosoft
May 01, 2025

When working with repeating structures in Logic Apps Data Mapper, you may run into situations where two sibling loops exist under the same parent. What if you need to access data from one loop while you’re inside the other?

This is where the Direct Access function, used in combination with Index, can save the day.

🧪 Scenario

In this pattern, we’re focusing on the schema nodes shown below:

📸 Source & Destination Schemas (with loops highlighted)

In the source schema:

  • Under the parent node VehicleTrips, we have two sibling arrays:
    • Vehicle → contains VehicleRegistration
    • Trips → contains trip-specific values like VehicleID, Distance, and Duration

In the destination schema:

  • We're mapping into the repeating node Looping/Trips/Trip
  • It expects each trip’s data along with a flattened VehicleRegistration value that combines both:
    • The current trip’s VehicleID
    • The corresponding vehicle’s VehicleRegistration

The challenge?

These two pieces of data live in two separate sibling arrays.

🧰 Try it yourself

📎 Download the sample files from GitHub

Place them into the following folders in your Logic Apps Standard project:

  • Artifacts → Source, destination and dependency schemas (.xsd)
  • Map Definitions → .lml map file
  • Maps → The .xslt file generated when you save the map

Then right-click the .lml file and select “Open with Data Mapper” in VS Code.

🛠️ Step-by-step Breakdown

✅ Step 1: Set up the loop over Trips

Start by mapping the repeating Trips array from the source to the destination's Trip node.

Within the loop, we map:

  • Distance
  • Duration

These are passed through To String functions before mapping, as the destination schema expects them as string values. As you map the child nodes, you will notice a loop automatically added on parent nodes (Trips->Trip)

📸 Mapping Distance and Duration nodes (context: we’re inside Trips loop)

🔍 Step 2: Use Index and Direct Access to bring in sibling loop values

Now we want to map the VehicleRegistration node at the destination by combining two values:

  • VehicleID (from the current trip)
  • VehicleRegistration (from the corresponding vehicle)

 

➡️ Note: Before we add the Index function, delete the auto-generated loop from Trips to Trip

 

To fetch the matching VehicleRegistration:

  • Use the Index function to capture the current position within the Trips loop

📸 Index setup for loop tracking

  • Use the Direct Access function to retrieve VehicleRegistration from the Vehicle array.

📘 Direct Access input breakdown

The Direct Access function takes three inputs:

  • Index – from the Index function, tells which item to access
  • Scope – set to Vehicle, the array you're pulling from
  • Target Node – VehicleRegistration, the value you want

This setup means: “From the Vehicle array, get the VehicleRegistration at the same index as the current trip.”

📸 Direct Access setup

 

🔧 Step 3: Concatenate and map the result

Use the Concat function to combine:

  • VehicleID (from Trips)
  • VehicleRegistration (from Vehicle, via Direct Access)

Map the result to VehicleRegistration in the destination.

📸 Concat result to VehicleRegistration


➡️ Note:
Before testing, delete the auto-generated loop from Vehicle to Trip

 

📸 Final map connections view

✅ Step 4: Test the output

Once your map is saved, open the Test panel and paste a sample payload.

You should see each Trip in the output contain:

  • The original Distance and Duration values (as strings)
  • A VehicleRegistration field combining the correct VehicleID and VehicleRegistration from the sibling array

📸 Sample Trip showing the combined nodes

💬 Feedback or ideas?

Have feedback or want to share a mapping challenge? Open an issue on GitHub

 

Updated May 01, 2025
Version 1.0

1 Comment

  • MegaAstronomy's avatar
    MegaAstronomy
    Copper Contributor

    Thanks for this article! Just to be clear the DirectAccess function above is getting the VehicleRegistration at the Index of the Vehicle loop that matches the index of the Trip loop as it goes through that loop. It's not somehow matching the VehicleID from Trips loop to the Vehicle loop. So this would require the Vehicle loop to have the same number or greater of items as the Trips loop. I think the DirectAccess function may help with want I'm trying to do, which is to take values from a loop in the source schema and flatten them to be used in the destination schema. Maybe to either take the first trip from a loop or the trip info for a specific VehicleID (to use the example here). I've been trying to make something like this work in the Data Mapper and haven't been successful yet. Any guidance would be most appreciated. These articles discussing the Data Mapper capabilities and functions are great. Keep them coming!