Azure Logic Apps: How to group objects by 'ReceiptId'?

Pekkola Jouni 0 Reputation points
2025-02-14T19:51:48.85+00:00

I have a problem, and I don't know how to solve it. I have a Logic App which gets data from D365FO

{
    "dataAreaId": "11",
    "TerminalId": "100402",
    "TransactionId": "xxxx",
    "LineNum": 1,
    "ReceiptId": "1004040220001"
},
{
    "dataAreaId": "11",
    "TerminalId": "100402",
    "TransactionId": "xxxxx",
    "LineNum": 2,
    "ReceiptId": "1004040220001"
}

I need to group receipts by ReceiptId. The data should look like this.

"1004040220001": [
{ "receiptnumber": "1004040220001", ... },
{ "receiptnumber": "1004040220001", ... }
],
"1004020000000099": [
{ "receiptnumber": "1004020000000099", ... }
],
}

My idea was i make PasonJson for hole dateset and after that i handle each data row in for-each loop. I tried to create the result as shown above. I created a GroupedReceipts object, which I initialized like this:

Capture

need help grouping data by receipt number. My expected output should look like above. Each receipt number should act as a key, and all corresponding entries should be grouped under it. How can I achieve this in Logic Apps?"

Azure Logic Apps
Azure Logic Apps
An Azure service that automates the access and use of data across clouds without writing code.
3,357 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Ranashekar Guda 95 Reputation points Microsoft Vendor
    2025-02-17T07:06:03.5233333+00:00

    Hi @Pekkola Jouni,
    Welcome to the Microsoft Q&A Platform! Thank you for asking your question here.

    To group receipts by ReceiptId in Azure Logic Apps, first initialize an empty GroupedReceipts object variable. Then, use a For-each loop to iterate through the array of receipt data. Inside the loop, add a Condition to check if the ReceiptId already exists as a key in the GroupedReceipts object.

    If it exists, append the current item to the existing list using union(). If it doesn’t exist, create a new key-value pair where the ReceiptId is the key, and the current item is the first element in the array. After the loop completes, the GroupedReceipts variable will contain the receipts grouped by ReceiptId, and you can use this for further processing.

    I hope the above provided information will helps in better understanding and solve your issue, if you have any further concerns, please feel free to reach out to us.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.