Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Logic Apps : For Each Inside a For Each - Fetching values from field in an array inside an array

Introduction

In last post Debatching(Splitting) XML Message in Logic Apps - ForEach and SplitOn  and we understood about how For each can be used to split/debatch messages.

In above scenario  we are using only one for each, whereas there can be situations where more than one For each would be required to solve the problem.


Scenario 


Say below is the purchase order and we need to take some action based on productName (value to be fetched). 

So we have two arrays to deal with
1. Products (having multiple product)
2. Product (having single product detail) within each products



Creating Logic App


Create a http based triggered logic app, followed by initializing a variable (in it we store value of productName field)



Next is to add first For Each which will iterate through array of Products, input to for each has to be an array and to do that we use xpath query as can be seen in below image




Using xpath above - we are asking to traverse through the triggerBody and look out of products node and if found add entry in  For each array.(All occurrence of products nodes are added).


xpath(xml(triggerbody()),'purchaseOrder/products')


The array will have all the products node , so if input has 10 Products node then the array formed using xpath will have 10 items in it, each representing a single products node.




Next, we need to loop through each product from products and for that we will use array which was created in first For each and for that syntax is - items('For_each') and using xpath - we are asking to traverse through the items('For_each') and look out of product node and if found add entry in  For each array.(All occurrence of product nodes are added).

xpath(xml(items('For_each')),'products/product')


last step is to use Set Variable  action where we fetch value of product name from each product node, and for that we will use array which was created in second  For each and for that syntax is - items('For_each_2') and using xpath - we get the current element value.


                xpath(xml(items('For_each_2')),'product/productName/text()')[0]










Related Post 

  • Getting Started with Logic Apps - Enterprise Application Integration
  • Getting Started with Logic Apps - EDI X12 Fundamentals
  • Getting Started with Logic Apps - What happened to the Request?
  • Getting Started with Logic Apps - Fundamentals
  • Getting Started with Logic Apps - AS2
  • Getting Started with Logic Apps - XML to EDI X12
  • The provided map definition is not valid
  • Required property 'content' expects a value but got null. Path ''.'
  • Getting Started with Logic Apps - File Routing
  • Installing and Configuring On Premises Data Gateway - By adding user to Active Directory
  • Inserting data in On Premises SQL Database using Logic Apps
  • Inserting Multiple Records In On Prem SQL Using Logic App
  • Check your request parameters to make sure the Path “” exists on your file system





    This post first appeared on TechFindings, please read the originial post: here

    Share the post

    Logic Apps : For Each Inside a For Each - Fetching values from field in an array inside an array

    ×

    Subscribe to Techfindings

    Get updates delivered right to your inbox!

    Thank you for your subscription

    ×