如何在 Power Automate Flow 中准备具有动态属性的 JSON 负载

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

我使用两个表“new_demotable001”和“new_metadatatable”。一个用于触发流程,另一个作为映射表。

通过使用两者,我想创建一个 JSON 有效负载,用于调用外部 API。 请帮我创建有效负载。

  1. 当 new_demotable001 添加新行时,流程触发。
  2. 我们将从表中收到的数据/属性是 - 注意:我删除了不必要的属性。
{
  "new_empname": "EmpName5",
  "new_demotable001id": "259ffaeb-a354-ef11-bfe3-000d3af2cd77",
  "new_empcontact": "555555555555",
  "new_name": "DemoDataTestin",
  "new_empstatus": 100000001,
  "_new_empstatus_label": "On-Boarded"
}
  1. 然后使用“List Rows”从“new_metadatatable”表中获取详细信息。
  2. 我们将从表中收到的数据/属性是 - 注意:我删除了不必要的属性。
{
  "@Microsoft.Dynamics.CRM.totalrecordcount": -1,
  "@Microsoft.Dynamics.CRM.totalrecordcountlimitexceeded": false,
  "@Microsoft.Dynamics.CRM.globalmetadataversion": "10896094",
  "value": [
    {
      "new_sirionattributename": "title",
      "new_dynamicsattributename": "new_empname"
      "new_name": "First"
    },
    {
      "new_sirionattributename": "test1",
      "new_dynamicsattributename": "new_empcontact",
      "new_name": "Second"
    },
    {
      "new_sirionattributename": "orgId",
      "new_dynamicsattributename": "new_empstatus",
      "new_name": "Third"
    }
  ]
}
  1. 现在,我想使用上述属性创建一个 JSON 有效负载。为了创建有效负载,我们将仅使用“new_metadatatable”中存在且也来自“new_demotable001”的那些属性。 -> 我使用的条件 - contains(triggerOutputs()?['body'], items('Apply_to_each')?['new_dynamicsattributename'])
  2. 对于上述数据集,预期输出有效负载应该是-
{
    "data":{
            "title": "EmpName5",
            "test1": "555555555555",
            "orgId": "100000001"
           }
}

尝试这个方法: screen snip of flow

详情:

Step: rowDemo
Action: Compose
Comment: you don't need this step, just for demo, this is the first JSON.

Step: metaData
Action: Compose
Comment: you don't need this step, just for demo, this is the second JSON.

Step: selectAttributes
Action: Select
From: outputs('metaData')['value']
Map left: item()?['new_sirionattributename']
Map right: outputs('rowDemo')?[item()?['new_dynamicsattributename']]

Step: payload
Action: Compose
Inputs:
{
  "data": @{json(
replace(
replace(
replace(
  string(body('selectAttributes')),
  '},{', ','), 
  '[', ''), 
  ']', '')
)}
}

备注:

  • selectAttributes
    步骤是映射属性及其值的关键步骤。
  • payload
    步骤将上一步中的数组转换为具有字符串操作的 JSON 对象。

为您提供最终的有效负载输出:
screen snip of the result

power-automate powerapps powerapps-canvas power-platform powerapps-modeldriven
1个回答
0
投票

尝试这个方法: screen snip of flow

详情:

Step: rowDemo
Action: Compose
Comment: you don't need this step, just for demo, this is the first JSON.

Step: metaData
Action: Compose
Comment: you don't need this step, just for demo, this is the second JSON.

Step: selectAttributes
Action: Select
From: outputs('metaData')['value']
Map left: item()?['new_sirionattributename']
Map right: outputs('rowDemo')?[item()?['new_dynamicsattributename']]

Step: payload
Action: Compose
Inputs:
{
  "data": @{json(
replace(
replace(
replace(
  string(body('selectAttributes')),
  '},{', ','), 
  '[', ''), 
  ']', '')
)}
}

备注:

  • selectAttributes
    步骤是映射属性及其值的关键步骤。
  • payload
    步骤将上一步中的数组转换为具有字符串操作的 JSON 对象。

为您提供最终的有效负载输出:
screen snip of the result

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