I have below json input to logic apps
[
{
"ACTIVITYID": "0002868073",
"STATUS": "Released",
"COMMENTS": [
{
"COMMENT": "Comment_1"
},
{
"COMMENT": "Comment_2"
}
]
},
{
"ACTIVITYID": "0002868071",
"STATUS": "Approved",
"COMMENTS": [
{
"COMMENT": "Comment_3"
},
{
"COMMENT": "Comment_4"
}
]
}
]
I want output like
0002868073 Released Comment_1 Comment_2
0002868071 Approved Comment_3 Comment_4
Here is my logic apps code view
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"For_each_-_ActivityLoop": {
"actions": {
"Append_to_string_variable_2": {
"inputs": {
"name": "FinalComment",
"value": "@variables('AppendInnerComment')"
},
"runAfter": {
"For_each_-_CommentsLoop": [
"Succeeded"
]
},
"type": "AppendToStringVariable"
},
"For_each_-_CommentsLoop": {
"actions": {
"Append_to_string_variable": {
"inputs": {
"name": "InnerComment",
"value": "@items('For_each_-_CommentsLoop')['COMMENT']"
},
"runAfter": {},
"type": "AppendToStringVariable"
},
"Append_to_string_variable_3": {
"inputs": {
"name": "AppendInnerComment",
"value": "@variables('InnerComment')"
},
"runAfter": {
"Append_to_string_variable": [
"Succeeded"
]
},
"type": "AppendToStringVariable"
}
},
"foreach": "@items('For_each_-_ActivityLoop')['COMMENTS']",
"runAfter": {},
"type": "Foreach"
},
"Set_variable_2": {
"inputs": {
"name": "FinalOutput",
"value": "@{items('For_each_-_ActivityLoop')['ACTIVITYID']}@{items('For_each_-_ActivityLoop')['STATUS']}@{variables('FinalComment')}"
},
"runAfter": {
"Append_to_string_variable_2": [
"Succeeded"
]
},
"type": "SetVariable"
}
},
"foreach": "@body('Parse_JSON')",
"runAfter": {
"Parse_JSON": [
"Succeeded"
]
},
"type": "Foreach"
},
"Initialize_FinalComment": {
"inputs": {
"variables": [
{
"name": "FinalComment",
"type": "string"
}
]
},
"runAfter": {
"Initialize_variable_-_AppendInnerComment": [
"Succeeded"
]
},
"type": "InitializeVariable"
},
"Initialize_FinalOutput": {
"inputs": {
"variables": [
{
"name": "FinalOutput",
"type": "string"
}
]
},
"runAfter": {
"Initialize_FinalComment": [
"Succeeded"
]
},
"type": "InitializeVariable"
},
"Initialize_InnerComment": {
"inputs": {
"variables": [
{
"name": "InnerComment",
"type": "string"
}
]
},
"runAfter": {
"Initialize_FinalOutput": [
"Succeeded"
]
},
"type": "InitializeVariable"
},
"Initialize_variable_-_AppendInnerComment": {
"inputs": {
"variables": [
{
"name": "AppendInnerComment",
"type": "string"
}
]
},
"runAfter": {},
"type": "InitializeVariable"
},
"Parse_JSON": {
"inputs": {
"content": "@triggerBody()",
"schema": {
"items": {
"properties": {
"ACTIVITYID": {
"type": "string"
},
"COMMENTS": {
"items": {
"properties": {
"COMMENT": {
"type": "string"
}
},
"required": [
"COMMENT"
],
"type": "object"
},
"type": "array"
},
"SAPUSERID": {
"type": "string"
},
"STATUS": {
"type": "string"
}
},
"required": [
"ACTIVITYID",
"STATUS",
"SAPUSERID",
"COMMENTS"
],
"type": "object"
},
"type": "array"
}
},
"runAfter": {
"Initialize_InnerComment": [
"Succeeded"
]
},
"type": "ParseJson"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {},
"triggers": {
"manual": {
"inputs": {
"method": "POST",
"schema": {
"items": {
"properties": {
"ACTIVITYID": {
"type": "string"
},
"COMMENTS": {
"items": {
"properties": {
"COMMENT": {
"type": "string"
}
},
"required": [
"COMMENT"
],
"type": "object"
},
"type": "array"
},
"SAPUSERID": {
"type": "string"
},
"STATUS": {
"type": "string"
}
},
"required": [
"ACTIVITYID",
"STATUS",
"SAPUSERID",
"COMMENTS"
],
"type": "object"
},
"type": "array"
}
},
"kind": "Http",
"type": "Request"
}
}
},
"parameters": {}
}
However, I get the output:
0002868073 Released Comment_1 Comment_1 Comment_2
0002868071 Approved Comment_1Comment_1Comment_2Comment_1Comment_1Comment_2Comment_1Comment_2Comment_3Comment_1Comment_2Comment_3Comment_4
Please advice to get the desired result.
2
Answers
I have used the below workflow to get the desired output.
Code–
Output–
Is this what you want?