skip to Main Content

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


  1. I have used the below workflow to get the desired output.

    enter image description here

    concat(items('For_each')?['ACTIVITYID'], ' ', items('For_each')?['STATUS'], ' ', items('For_each')?['COMMENTS'][0]['COMMENT'], ' ',items('For_each')?['COMMENTS'][1]['COMMENT'])
    

    enter image description here
    enter image description here

    Code

    {
        "definition": {
            "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
            "actions": {
                "Compose": {
                    "inputs": "@variables('Output')",
                    "runAfter": {
                        "For_each": [
                            "Succeeded"
                        ]
                    },
                    "type": "Compose"
                },
                "For_each": {
                    "actions": {
                        "Append_to_string_variable": {
                            "inputs": {
                                "name": "Output",
                                "value": "@{concat(items('For_each')?['ACTIVITYID'], ' ', items('For_each')?['STATUS'], ' ', items('For_each')?['COMMENTS'][0]['COMMENT'], ' ',items('For_each')?['COMMENTS'][1]['COMMENT'])} "
                            },
                            "runAfter": {},
                            "type": "AppendToStringVariable"
                        }
                    },
                    "foreach": "@variables('Input')",
                    "runAfter": {
                        "Output": [
                            "Succeeded"
                        ]
                    },
                    "runtimeConfiguration": {
                        "concurrency": {
                            "repetitions": 1
                        }
                    },
                    "type": "Foreach"
                },
                "Input": {
                    "inputs": {
                        "variables": [
                            {
                                "name": "Input",
                                "type": "array",
                                "value": [
                                    {
                                        "ACTIVITYID": "0002868073",
                                        "COMMENTS": [
                                            {
                                                "COMMENT": "Comment_1"
                                            },
                                            {
                                                "COMMENT": "Comment_2"
                                            }
                                        ],
                                        "STATUS": "Released"
                                    },
                                    {
                                        "ACTIVITYID": "0002868071",
                                        "COMMENTS": [
                                            {
                                                "COMMENT": "Comment_3"
                                            },
                                            {
                                                "COMMENT": "Comment_4"
                                            }
                                        ],
                                        "STATUS": "Approved"
                                    }
                                ]
                            }
                        ]
                    },
                    "runAfter": {},
                    "type": "InitializeVariable"
                },
                "Output": {
                    "inputs": {
                        "variables": [
                            {
                                "name": "Output",
                                "type": "string"
                            }
                        ]
                    },
                    "runAfter": {
                        "Input": [
                            "Succeeded"
                        ]
                    },
                    "type": "InitializeVariable"
                }
            },
            "contentVersion": "1.0.0.0",
            "outputs": {},
            "parameters": {},
            "triggers": {
                "manual": {
                    "inputs": {},
                    "kind": "Http",
                    "type": "Request"
                }
            }
        },
        "parameters": {}
    }
    

    Output

    enter image description here

    enter image description here

    enter image description here

    Login or Signup to reply.
  2. Is this what you want?

    Result

    {
        "definition": {
            "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
            "actions": {
                "For_Each_Activity": {
                    "actions": {
                        "Append_To_Final_Array": {
                            "inputs": {
                                "name": "Final Array",
                                "value": "@{items('For_Each_Activity')['ACTIVITYID']} @{items('For_Each_Activity')['STATUS']} @{trim(variables('Concatenated Comments'))}"
                            },
                            "runAfter": {
                                "For_Each_Comment": [
                                    "Succeeded"
                                ]
                            },
                            "type": "AppendToArrayVariable"
                        },
                        "For_Each_Comment": {
                            "actions": {
                                "Append_To_Concatenated_Comments": {
                                    "inputs": {
                                        "name": "Concatenated Comments",
                                        "value": "@{items('For_Each_Comment')['COMMENT']} "
                                    },
                                    "runAfter": {},
                                    "type": "AppendToStringVariable"
                                }
                            },
                            "foreach": "@items('For_Each_Activity')['COMMENTS']",
                            "runAfter": {
                                "Set_Concatenated_Comments": [
                                    "Succeeded"
                                ]
                            },
                            "type": "Foreach"
                        },
                        "Set_Concatenated_Comments": {
                            "inputs": {
                                "name": "Concatenated Comments",
                                "value": "@{string('')}"
                            },
                            "runAfter": {},
                            "type": "SetVariable"
                        }
                    },
                    "foreach": "@triggerBody()",
                    "runAfter": {
                        "Initialize_Concatenated_Comments": [
                            "Succeeded"
                        ]
                    },
                    "runtimeConfiguration": {
                        "concurrency": {
                            "repetitions": 1
                        }
                    },
                    "type": "Foreach"
                },
                "Initialize_Concatenated_Comments": {
                    "inputs": {
                        "variables": [
                            {
                                "name": "Concatenated Comments",
                                "type": "string"
                            }
                        ]
                    },
                    "runAfter": {
                        "Initialize_Final_Array": [
                            "Succeeded"
                        ]
                    },
                    "type": "InitializeVariable"
                },
                "Initialize_Final_Array": {
                    "inputs": {
                        "variables": [
                            {
                                "name": "Final Array",
                                "type": "array"
                            }
                        ]
                    },
                    "runAfter": {},
                    "type": "InitializeVariable"
                },
                "Initialize_Result": {
                    "inputs": {
                        "variables": [
                            {
                                "name": "Result",
                                "type": "string",
                                "value": "@{join(variables('Final Array'), 'rn')}"
                            }
                        ]
                    },
                    "runAfter": {
                        "For_Each_Activity": [
                            "Succeeded"
                        ]
                    },
                    "type": "InitializeVariable"
                }
            },
            "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": {}
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search