逻辑应用程序(电源自动化)从规划器计划的任务中提取清单项目

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

我有一个

'get the checklist Items for each task from the template plan (task details)'
行动 这是一个 http get

https://graph.microsoft.com/v1.0/planner/tasks/@{items('For_each_template_task')?['id']}/details

然后是

'Parse JSON testing'
动作

架构:


{
    "properties": {
        "@@odata.context": {
            "type": "string"
        },
        "@@odata.etag": {
            "type": "string"
        },
        "checklist": {
            "additionalProperties": {
                "properties": {
                    "@@odata.type": {
                        "type": "string"
                    },
                    "isChecked": {
                        "type": "boolean"
                    },
                    "lastModifiedBy": {},
                    "lastModifiedDateTime": {
                        "type": "string"
                    },
                    "orderHint": {
                        "type": "string"
                    },
                    "title": {
                        "type": "string"
                    }
                },
                "type": "object"
            },
            "type": "object"
        },
        "description": {
            "type": "string"
        },
        "id": {
            "type": "string"
        },
        "previewType": {
            "type": "string"
        },
        "references": {
            "properties": {},
            "type": "object"
        }
    },
    "type": "object"
}

内容

@{body('get_the_checklist_Items_for_each_task_from_the_templateplan(task_details)')}

输出数据

{
  "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#planner/tasks('2B69MwLkekuzBBu38EcaDpcANQ0l')/details/$entity",
  "@odata.etag": "W/\"JzEtVGFza0RldGFpbHMgQEBAQEBAQEBAQEBAQEBARCc=\"",
  "id": "2B69MwLkekuzBBu38EcaDpcANQ0l",
  "description": "",
  "previewType": "checklist",
  "references": {},
  "checklist": {
    "14037": {
      "@odata.type": "#microsoft.graph.plannerChecklistItem",
      "isChecked": false,
      "title": "test1",
      "orderHint": "8585Fg",
      "lastModifiedDateTime": "0001-01-01T00:00:00Z",
      "lastModifiedBy": null
    },
    "36310": {
      "@odata.type": "#microsoft.graph.plannerChecklistItem",
      "isChecked": false,
      "title": "test2",
      "orderHint": "8586002405mV",
      "lastModifiedDateTime": "0001-01-01T00:00:00Z",
      "lastModifiedBy": null
    },
    "45221": {
      "@odata.type": "#microsoft.graph.plannerChecklistItem",
      "isChecked": false,
      "title": "test3",
      "orderHint": "8586002406569253572P.",
      "lastModifiedDateTime": "0001-01-01T00:00:00Z",
      "lastModifiedBy": null
    },
    "61052": {
      "@odata.type": "#microsoft.graph.plannerChecklistItem",
      "isChecked": false,
      "title": "test4",
      "orderHint": "8585\\Y",
      "lastModifiedDateTime": "0001-01-01T00:00:00Z",
      "lastModifiedBy": null
    }
  }
}

诸如

14037
36310
45221
61052 
之类的键是动态键(这些是任务中的清单项目,位于规划器计划的存储桶中)这些来自模板计划

对于每个清单项目,我还想在目的地规划器中为特定任务创建清单

在我正在使用的每个

@createArray(outputs('Parse_JSON_testing'))
但这里的 foreach 循环只运行一次,在这种情况下应该运行 4 次

for each
里面我有
'create checklist items on the new tasks'
动作 一个http补丁 这应该将清单项目放入任务中,基本上我想做的是克隆计划及其存储桶、任务和清单项目。存储桶、任务的创建工作完美,唯一的问题是清单项(子任务)

我做错了什么?我怎样才能让我的 for every 正确迭代?

我尝试了不同的方法,包括选择和过滤操作,但我无法做到正确。

microsoft-graph-api azure-logic-apps power-automate microsoft-planner microsoft-graph-plannertasks
1个回答
0
投票

我有两种方法给你......

高级数据操作

执行此操作的一个好方法是使用高级数据操作连接器。 它有一个名为“Json Properties to Name/Value Pair Array”的操作,它将分解数据并使您能够理解属性名称及其关联值。

https://statesolutions.com.au/json-properties-to-name-value-pair-array/

将该数据传递到该操作中将产生此结果...

[ { "propertyName": "id", "propertyType": "String", "propertyValue": "2B69MwLkekuzBBu38EcaDpcANQ0l" }, { "propertyName": "description", "propertyType": "String", "propertyValue": "" }, { "propertyName": "previewType", "propertyType": "String", "propertyValue": "checklist" }, { "propertyName": "references", "propertyType": "Object", "propertyValue": [] }, { "propertyName": "checklist", "propertyType": "Object", "propertyValue": [ { "propertyName": "14037", "propertyType": "Object", "propertyValue": [ { "propertyName": "isChecked", "propertyType": "Boolean", "propertyValue": false }, { "propertyName": "title", "propertyType": "String", "propertyValue": "test1" }, { "propertyName": "orderHint", "propertyType": "String", "propertyValue": "8585Fg" }, { "propertyName": "lastModifiedDateTime", "propertyType": "Date", "propertyValue": "0001-01-01T00:00:00Z" }, { "propertyName": "lastModifiedBy", "propertyType": "Null", "propertyValue": null }, { "propertyName": "@odata.type", "propertyType": "String", "propertyValue": "#microsoft.graph.plannerChecklistItem" } ] }, { "propertyName": "36310", "propertyType": "Object", "propertyValue": [ { "propertyName": "isChecked", "propertyType": "Boolean", "propertyValue": false }, { "propertyName": "title", "propertyType": "String", "propertyValue": "test2" }, { "propertyName": "orderHint", "propertyType": "String", "propertyValue": "8586002405mV" }, { "propertyName": "lastModifiedDateTime", "propertyType": "Date", "propertyValue": "0001-01-01T00:00:00Z" }, { "propertyName": "lastModifiedBy", "propertyType": "Null", "propertyValue": null }, { "propertyName": "@odata.type", "propertyType": "String", "propertyValue": "#microsoft.graph.plannerChecklistItem" } ] }, { "propertyName": "45221", "propertyType": "Object", "propertyValue": [ { "propertyName": "isChecked", "propertyType": "Boolean", "propertyValue": false }, { "propertyName": "title", "propertyType": "String", "propertyValue": "test3" }, { "propertyName": "orderHint", "propertyType": "String", "propertyValue": "8586002406569253572P." }, { "propertyName": "lastModifiedDateTime", "propertyType": "Date", "propertyValue": "0001-01-01T00:00:00Z" }, { "propertyName": "lastModifiedBy", "propertyType": "Null", "propertyValue": null }, { "propertyName": "@odata.type", "propertyType": "String", "propertyValue": "#microsoft.graph.plannerChecklistItem" } ] }, { "propertyName": "61052", "propertyType": "Object", "propertyValue": [ { "propertyName": "isChecked", "propertyType": "Boolean", "propertyValue": false }, { "propertyName": "title", "propertyType": "String", "propertyValue": "test4" }, { "propertyName": "orderHint", "propertyType": "String", "propertyValue": "8585\\Y" }, { "propertyName": "lastModifiedDateTime", "propertyType": "Date", "propertyValue": "0001-01-01T00:00:00Z" }, { "propertyName": "lastModifiedBy", "propertyType": "Null", "propertyValue": null }, { "propertyName": "@odata.type", "propertyType": "String", "propertyValue": "#microsoft.graph.plannerChecklistItem" } ] } ] }, { "propertyName": "@odata.context", "propertyType": "String", "propertyValue": "https://graph.microsoft.com/v1.0/$metadata#planner/tasks('2B69MwLkekuzBBu38EcaDpcANQ0l')/details/$entity" }, { "propertyName": "@odata.etag", "propertyType": "String", "propertyValue": "W/\"JzEtVGFza0RldGFpbHMgQEBAQEBAQEBAQEBAQEBARCc=\"" } ]

从那里,您可以挑选并循环遍历属性名称,并从原始结构中提取相关数据。

XML

您可以将其转换为 XML 并以这种方式进行操作,但是名称为数字的属性并不总是按照您想要的方式转换,然后您必须完成工作才能获得正确的结果。

它将属性名称

14037

转换为 XML 中的元素名称

_x0031_4037
。 原因是由于管理 XML 结构中任何元素名称的第一个字符的规则,它不应以数字开头。
如果您愿意,我也可以向您展示该解决方案,但如果任何动态属性名称不是数字,您将需要确定逻辑中的分叉来处理该问题。

转换为 XML 的数据看起来像这样......

<root odata.context="https://graph.microsoft.com/v1.0/$metadata#planner/tasks('2B69MwLkekuzBBu38EcaDpcANQ0l')/details/$entity" odata.etag="W/&quot;JzEtVGFza0RldGFpbHMgQEBAQEBAQEBAQEBAQEBARCc=&quot;"> <id>2B69MwLkekuzBBu38EcaDpcANQ0l </id> <description> </description> <previewType>checklist </previewType> <references /> <checklist> <_x0031_4037 odata.type="#microsoft.graph.plannerChecklistItem"> <isChecked>false </isChecked> <title>test1 </title> <orderHint>8585Fg </orderHint> <lastModifiedDateTime>0001-01-01T00:00:00Z </lastModifiedDateTime> <lastModifiedBy /> </_x0031_4037> <_x0033_6310 odata.type="#microsoft.graph.plannerChecklistItem"> <isChecked>false </isChecked> <title>test2 </title> <orderHint>8586002405mV </orderHint> <lastModifiedDateTime>0001-01-01T00:00:00Z </lastModifiedDateTime> <lastModifiedBy /> </_x0033_6310> <_x0034_5221 odata.type="#microsoft.graph.plannerChecklistItem"> <isChecked>false </isChecked> <title>test3 </title> <orderHint>8586002406569253572P. </orderHint> <lastModifiedDateTime>0001-01-01T00:00:00Z </lastModifiedDateTime> <lastModifiedBy /> </_x0034_5221> <_x0036_1052 odata.type="#microsoft.graph.plannerChecklistItem"> <isChecked>false </isChecked> <title>test4 </title> <orderHint>8585\Y </orderHint> <lastModifiedDateTime>0001-01-01T00:00:00Z </lastModifiedDateTime> <lastModifiedBy /> </_x0036_1052> </checklist> </root>

这样,我们就可以使用一些操作来获取元素的名称,这是演示该方法的流程...

Flow

初始化数据

初始化变量 这就是您的 JSON 数据。

初始化数据。根属性

初始化变量 为了让JSON成功转换为XML,我们需要添加一个根属性。 这个变量的类型是

Object

这是这样做的表达...

@{json(concat('{ "root": ', variables('Data'), '}'))}

将 XML 编写为数据

(Compose) 这个很简单,表达方式就是...

@{xml(variables('Data w. Root Property'))}

撰写清单元素

(撰写) 我们现在想要获取

<checklist>

节点下方的所有元素,为此,我们需要在其顶部运行 Xpath 查询,这就是表达式 ...

@{xpath(outputs('Compose_Data_As_XML'), '//checklist/*')}

这给了我们这个回来......

[ { "$content-type": "application/xml;charset=utf-8", "$content": "PF94MDAzMV80MDM3IG9kYXRhLnR5cGU9IiNtaWNyb3NvZnQuZ3JhcGgucGxhbm5lckNoZWNrbGlzdEl0ZW0iPg0KICA8aXNDaGVja2VkPmZhbHNlPC9pc0NoZWNrZWQ+DQogIDx0aXRsZT50ZXN0MTwvdGl0bGU+DQogIDxvcmRlckhpbnQ+ODU4NUZnPC9vcmRlckhpbnQ+DQogIDxsYXN0TW9kaWZpZWREYXRlVGltZT4wMDAxLTAxLTAxVDAwOjAwOjAwWjwvbGFzdE1vZGlmaWVkRGF0ZVRpbWU+DQogIDxsYXN0TW9kaWZpZWRCeSAvPg0KPC9feDAwMzFfNDAzNz4=" }, { "$content-type": "application/xml;charset=utf-8", "$content": "PF94MDAzM182MzEwIG9kYXRhLnR5cGU9IiNtaWNyb3NvZnQuZ3JhcGgucGxhbm5lckNoZWNrbGlzdEl0ZW0iPg0KICA8aXNDaGVja2VkPmZhbHNlPC9pc0NoZWNrZWQ+DQogIDx0aXRsZT50ZXN0MjwvdGl0bGU+DQogIDxvcmRlckhpbnQ+ODU4NjAwMjQwNW1WPC9vcmRlckhpbnQ+DQogIDxsYXN0TW9kaWZpZWREYXRlVGltZT4wMDAxLTAxLTAxVDAwOjAwOjAwWjwvbGFzdE1vZGlmaWVkRGF0ZVRpbWU+DQogIDxsYXN0TW9kaWZpZWRCeSAvPg0KPC9feDAwMzNfNjMxMD4=" }, { "$content-type": "application/xml;charset=utf-8", "$content": "PF94MDAzNF81MjIxIG9kYXRhLnR5cGU9IiNtaWNyb3NvZnQuZ3JhcGgucGxhbm5lckNoZWNrbGlzdEl0ZW0iPg0KICA8aXNDaGVja2VkPmZhbHNlPC9pc0NoZWNrZWQ+DQogIDx0aXRsZT50ZXN0MzwvdGl0bGU+DQogIDxvcmRlckhpbnQ+ODU4NjAwMjQwNjU2OTI1MzU3MlAuPC9vcmRlckhpbnQ+DQogIDxsYXN0TW9kaWZpZWREYXRlVGltZT4wMDAxLTAxLTAxVDAwOjAwOjAwWjwvbGFzdE1vZGlmaWVkRGF0ZVRpbWU+DQogIDxsYXN0TW9kaWZpZWRCeSAvPg0KPC9feDAwMzRfNTIyMT4=" }, { "$content-type": "application/xml;charset=utf-8", "$content": "PF94MDAzNl8xMDUyIG9kYXRhLnR5cGU9IiNtaWNyb3NvZnQuZ3JhcGgucGxhbm5lckNoZWNrbGlzdEl0ZW0iPg0KICA8aXNDaGVja2VkPmZhbHNlPC9pc0NoZWNrZWQ+DQogIDx0aXRsZT50ZXN0NDwvdGl0bGU+DQogIDxvcmRlckhpbnQ+ODU4NVxZPC9vcmRlckhpbnQ+DQogIDxsYXN0TW9kaWZpZWREYXRlVGltZT4wMDAxLTAxLTAxVDAwOjAwOjAwWjwvbGFzdE1vZGlmaWVkRGF0ZVRpbWU+DQogIDxsYXN0TW9kaWZpZWRCeSAvPg0KPC9feDAwMzZfMTA1Mj4=" } ]

...这种形式不太有用,因此下一步将完成工作以获取所需的内容。

选择属性名称

选择 这是丑陋的部分,但它所做的就是让你无需循环即可获得所需的内容。

这是

Select

操作的定义...

Select ...这些是需要依次粘贴的

two

表达式... @{replace(split(xpath(xml(base64ToString(item()['$content'])), 'name(/*)'), '_')[1], 'x003', '')}@{last(split(xpath(xml(base64ToString(item()['$content'])), 'name(/*)'), '_'))}

...就像我说的,它有点难看,但可以完成工作。

这就是结果...

[ { "PropertyName": "14037" }, { "PropertyName": "36310" }, { "PropertyName": "45221" }, { "PropertyName": "61052" } ]

使用这两种方法允许您循环属性名称并从原始 JSON 数据中动态提取它们的值。

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