Cool hack to transform data in Azure logic apps, using simple expressions (and no code)
Amigos, here goes a very cool hack to handle an incoming payload in your Azure Logic Apps, that can create any type of complex transformation, using just expression and variables -- nothing else. I have covered how to transform using Data-mappers on another previous blog (https://community.dynamics.com/blogs/post/?postid=d7eda435-952b-ef11-840a-6045bddad7eb), but this one is even easier.
Check it out:
Background:
We have an incoming purchase order payload that cumbersomely looks like this:
{
"OrderNum": "PO000111",
"VendorCode": "v0001",
"NoOfLines": 3,
"Currency": "euro",
"PaymentTerms": "14d",
"OrderStatus": "Received",
"Invoiced": "No",
"Lines" :
[
{
"ItemId": "I0001",
"Qty": 12,
"Price": 1000,
"LineNum": 1
},
{
"ItemId": "I0002",
"Qty": 20,
"Price": 2000,
"LineNum": 2
},
{
"ItemId": "I0003",
"Qty": 22,
"Price": 3000,
"LineNum": 3
}
]
}
So we have a header section where we have Purchase Order Number, vendor code, Payment terms Id, Order status, Invoice status. And then we have Lines, where we have an array containing elements bearing infoirmation like Item id, Qty, Price and other details.
We have to transform it to make it look this:
In the output, we are summing up the Qtys and also creating another JSON within the main JSON, where are capturing additional details, where each of the Enums like Payment terms, Order status, Invoice Status are getting replaced by integer values, instead of actual literal values. Which means the destination system doesn't undeerstand Payment Terms as 14d, 28d or 60d, but treats it as 0, 1, 2, 3, etc. Similarly Order Status as Invoiced, Packing slip, Invoiced, etc. are also to be transformed as 0, 1, 2, etc. Baiscally there is a map between the values, and the expectation is the Logic app should be able to convert between map values.
Step 1:
Let us start with the basic Azure Logic of accepting HTTP request logic app trigger:
Paste the source payload and the Logic app will generate the schema.
Step 2:
Step 4:
Important part is the logic by which the selection is happening between the supplied value to the target value. For example, see how the Payment term value of 28d is tarnslated as 1:
Comments
Post a Comment