将 D365 F&O 数据事件转换为可管理的 json 格式

问题描述 投票:0回答:1

我有一个服务总线定期推送数据事件。我的任务是使用 Azure 逻辑应用将数据转换为更易于管理的格式。 我简化了从数据事件接收到的数据。

我给出的数据采用这种格式,但字段数量和字段名称可能有所不同:

{
    "body": {
        "InputParameters": [
            {
                "value": {
                    "Attributes": [
                        {
                            "key": "first_name",
                            "value": "john"
                        },
                        {
                            "key": "last_name",
                            "value": "doe"
                        },
                        {
                            "key": "age",
                            "value": {
                                "Value": 25
                            }
                        }
                    ]
                }
            }
        ]
    }
}

我想最终得到这个输出:

{
    "first_name": "john",
    "last_name": "doe",
    "age": 25
}

我尝试过像这样使用“选择”

concat(item()?['key'], ': ', item()?['value'])

生成此输出:

[
    "first_name: john",
    "last_name: doe",
    "age: 25"
]

这离期望的结果不远,但还没有完全达到。

我也尝试了一种与此处提到的解决方案非常相似的解决方案,但我的数据集至少包含 400 行,因此最终需要一分钟多的时间。

我很茫然。如何才能实现这一目标?

json azure azure-logic-apps microsoft-dynamics
1个回答
0
投票

我也尝试了一种与此处提到的解决方案非常相似的解决方案,但我的数据集至少包含 400 行,因此最终需要一分钟多的时间。

据我所知,无论您在逻辑应用程序中选择什么操作,都需要大量时间来对 400 行执行一组操作。您可以按照此

SO-Thread 或下面的方法使用 Foreach 循环。

工作流程-

enter image description here

enter image description here enter image description hereenter image description here

选择:-

From: first(body('Parse_JSON')?['InputParameters'])?['value']?['Attributes'] Map: addProperty(variables('result'),item()?['key'],item()?['value'])

撰写:-

Compose: string(body('Select')) Compose 2: replace(replace(replace(outputs('Compose'), '[{', '{'), '}]', '}'), '},{', ',')

代码-

{ "definition": { "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#", "actions": { "Add_Property_Data": { "inputs": { "variables": [ { "name": "Result", "type": "object", "value": {} } ] }, "runAfter": { "Initial_Data": [ "Succeeded" ] }, "type": "InitializeVariable" }, "Compose": { "inputs": "@string(body('Select'))", "runAfter": { "Select": [ "Succeeded" ] }, "type": "Compose" }, "Compose_2": { "inputs": "@replace(replace(replace(outputs('Compose'), '[{', '{'), '}]', '}'), '},{', ',')", "runAfter": { "Compose": [ "Succeeded" ] }, "type": "Compose" }, "Initial_Data": { "inputs": { "variables": [ { "name": "Data", "type": "string", "value": "{\n \"InputParameters\": [\n {\n \"value\": {\n \"Attributes\": [\n {\n \"key\": \"first_name\",\n \"value\": \"john\"\n },\n {\n \"key\": \"last_name\",\n \"value\": \"doe\"\n },\n {\n \"key\": \"age\",\n \"value\": \"25\"\n }\n ]\n }\n }\n ]\n }" } ] }, "runAfter": {}, "type": "InitializeVariable" }, "Parse_JSON": { "inputs": { "content": "@variables('Data')", "schema": { "properties": { "InputParameters": { "items": { "properties": { "value": { "properties": { "Attributes": { "items": { "properties": { "key": { "type": "string" }, "value": { "type": "string" } }, "required": [ "key", "value" ], "type": "object" }, "type": "array" } }, "type": "object" } }, "required": [ "value" ], "type": "object" }, "type": "array" } }, "type": "object" } }, "runAfter": { "Add_Property_Data": [ "Succeeded" ] }, "type": "ParseJson" }, "Select": { "inputs": { "from": "@first(body('Parse_JSON')?['InputParameters'])?['value']?['Attributes']", "select": "@addProperty(variables('result'),item()?['key'],item()?['value'])" }, "runAfter": { "Parse_JSON": [ "Succeeded" ] }, "type": "Select" } }, "contentVersion": "1.0.0.0", "outputs": {}, "parameters": {}, "triggers": { "manual": { "inputs": { "schema": { "properties": { "InputParameters": { "items": { "properties": { "value": { "properties": { "Attributes": { "items": { "properties": { "key": { "type": "string" }, "value": { "type": "string" } }, "required": [ "key", "value" ], "type": "object" }, "type": "array" } }, "type": "object" } }, "required": [ "value" ], "type": "object" }, "type": "array" } }, "type": "object" } }, "kind": "Http", "type": "Request" } } }, "parameters": {} }

输出-

enter image description here enter image description hereenter image description here

© www.soinside.com 2019 - 2024. All rights reserved.