web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / CurrentItem in For Eac...
Power Automate
Answered

CurrentItem in For Each loop not using correct XML Variable

(0) ShareShare
ReportReport
Posted on by 3

I'm attempting to concatenate two element values into one from a series of child items like the below XML block. My XPath expression is working correctly and gives the correct number of items in the list. But when I try to use the CurrentItem in this list to Get or Set an XML Element Value it uses the first record in the list instead of the current one. However using Insert XML with the same CurrentItem variable inserts the correct one.

 

<transportInstructionConsignmentItem>
	<lineItemNumber>1</lineItemNumber>
	<transportCargoCharacteristics>
		<cargoTypeCode>14</cargoTypeCode>
		<cargoTypeDescription languageCode="en">TypeDescription</cargoTypeDescription>
		<totalPackageQuantity>4</totalPackageQuantity
		<totalItemQuantity>2.0</totalItemQuantity>
	</transportCargoCharacteristics>
	<handlingInstruction>
		<transportTemperature>
			<maximumTemperature>4.00</maximumTemperature>
			<minimumTemperature>4.00</minimumTemperature>
		</transportTemperature>
	</handlingInstruction>
	<logisticUnit>
		<packageTypeCode>Type</packageTypeCode>
		<tradeItemQuantity>100</tradeItemQuantity>
		<tradeItemReference>ItemRef</tradeItemReference>
		<tradeItemDescription>Test</tradeItemDescription>
	</logisticUnit>
</transportInstructionConsignmentItem>

Doing the exact same thing with loop and another XPath on the node list using the LoopIndex works as expected.

 

Is this a bug, or am I using the For Each wrong? I feel like it should work and it's weird that the different XML actions are point to different variables. Any ideas?

PADForEach.png
VariablesDuringRun.png
PADLoop.png
  • Verified answer
    Agnius Bartninkas Profile Picture
    Most Valuable Professional on at

    We have reported this behavior to Microsoft a few years ago, thinking this was a bug, and they said this is the expected behavior of the Get XML element value action. It doesn't actually target the list, but instead the original XML and as such, it gets the first item all the time. In order to get a specific item, you do in fact need to use a simple Loop with an index and the execute an XPath expression instead.

    -------------------------------------------------------------------------
    If I have answered your question, please mark it as the preferred solution. If you like my response, please give it a Thumbs Up.

    I also provide paid consultancy and development services using Power Automate. If you're interested, DM me and we can discuss it.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Automate

#1
11manish Profile Picture

11manish 233 Super User 2026 Season 2

#2
David_MA Profile Picture

David_MA 227 Super User 2026 Season 2

#3
Mohsin Ali Profile Picture

Mohsin Ali 178

Last 30 days Overall leaderboard