【问题标题】:Generate dynamic content in azure logic app在 Azure 逻辑应用中生成动态内容
【发布时间】:2019-07-29 07:42:53
【问题描述】:

我想在 azure logic APP 中为我的 HTTP 任务创建这样一个主体

{
  "CommitMode": "transactional",
  "MaxParallelism": 20,
  "Objects": [
    {
      "partition": "Table_2019-03-27",
      "table": "Table"
    },
     {
      "partition": "Table_2019-03-28",
      "table": "Table"
    },
    {
      "partition": "Table_2019-03-29",
      "table": "Table"
    }
  ],
  "RetryCount": 0,
  "Type": "Full"
}

我想自动生成正文部分,你可以看到只有partition 是变化的,它是Table_Date 的组合你有什么想法我怎么能在天蓝色中实现这样的东西逻辑应用?

【问题讨论】:

  • 您从哪里以及如何获得这些值?他们的号码是固定的吗?它们的初始格式是什么?
  • 我想在我的逻辑应用程序中定义一个具有默认值的变量,即 2019-03-27,然后我想生成接下来的十天并将它们整合到我的身体中
  • 日期是否与今天的日期有某种关联?
  • @AdAstra 它与今天的日期无关

标签: json azure azure-logic-apps


【解决方案1】:

您似乎正在尝试通过 REST API 刷新 Azure 分析服务。

假设您已定义日期(或作为参数传递)

然后为日期创建临时变量,如下所示

现在您创建 until 循环,该循环迭代直到数组将具有您想要的天数长度。在本例 10 中,您可以将其作为参数传递。

您在这里看到的第一个表达式是

length(variables('Dates'))

追加到数组变量的表达式是

formatDateTime(addDays(variables('StartDate'), iterationIndexes('Until')),'yyyy-MM-dd')

然后简单地将body创建为

这里的表达式是

concat('{"partition": "Table_',join(variables('Dates'), '","table": "Table"},{"partition": "Table_'),'","table": "Table"}')

你的输出看起来像

{
  "CommitMode": "transactional",
  "MaxParallelism": 20,
  "Objects": [
    {"partition": "Table_2019-03-27","table": "Table"},
    {"partition": "Table_2019-03-28","table": "Table"},
    {"partition": "Table_2019-03-29","table": "Table"},
    {"partition": "Table_2019-03-30","table": "Table"},
    {"partition": "Table_2019-03-31","table": "Table"},
    {"partition": "Table_2019-04-01","table": "Table"},
    {"partition": "Table_2019-04-02","table": "Table"},
    {"partition": "Table_2019-04-03","table": "Table"},
    {"partition": "Table_2019-04-04","table": "Table"},
    {"partition": "Table_2019-04-05","table": "Table"}
  ],
  "RetryCount": 0,
  "Type": "Full"
}

如果您想获得有关如何执行此操作的一般建议,我有一篇关于如何在此处的逻辑应用程序中执行此操作的文章

如果您想了解有关逻辑应用的更多信息,请查看我关于逻辑应用的视频系列

完整代码供参考

{
  "definition": {
    "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
    "actions": {
      "Initialize_Body": {
        "inputs": {
          "variables": [
            {
              "name": "body",
              "type": "String",
              "value": "{\n  \"CommitMode\": \"transactional\",\n  \"MaxParallelism\": 20,\n  \"Objects\": [\n  @{concat('{\"partition\": \"Table_',join(variables('Dates'), '\",\"table\": \"Table\"},{\"partition\": \"Table_'),'\",\"table\": \"Table\"}')}\n  ],\n  \"RetryCount\": 0,\n  \"Type\": \"Full\"\n}"
            }
          ]
        },
        "runAfter": {
          "Until": [
            "Succeeded"
          ]
        },
        "type": "InitializeVariable"
      },
      "Initialize_Start_Date": {
        "inputs": {
          "variables": [
            {
              "name": "StartDate",
              "type": "String",
              "value": "2019-03-27"
            }
          ]
        },
        "runAfter": {},
        "type": "InitializeVariable"
      },
      "Initialize_variable": {
        "inputs": {
          "variables": [
            {
              "name": "Dates",
              "type": "Array",
              "value": []
            }
          ]
        },
        "runAfter": {
          "Initialize_Start_Date": [
            "Succeeded"
          ]
        },
        "type": "InitializeVariable"
      },
      "Until": {
        "actions": {
          "Append_to_array_variable": {
            "inputs": {
              "name": "Dates",
              "value": "@formatDateTime(addDays(variables('StartDate'), iterationIndexes('Until')),'yyyy-MM-dd')"
            },
            "runAfter": {},
            "type": "AppendToArrayVariable"
          }
        },
        "expression": "@equals(length(variables('Dates')), 10)",
        "limit": {
          "count": 60,
          "timeout": "PT1H"
        },
        "runAfter": {
          "Initialize_variable": [
            "Succeeded"
          ]
        },
        "type": "Until"
      }
    },
    "contentVersion": "1.0.0.0",
    "outputs": {},
    "parameters": {},
    "triggers": {
      "manual": {
        "inputs": {
          "schema": {}
        },
        "kind": "Http",
        "type": "Request"
      }
    }
  }
}

【讨论】:

    【解决方案2】:

    1.如果您的数据是固定的。您可以使用Compose action 生成json。

    2.但是,由于您需要通过计算获得所需的日期,并且逻辑应用程序中没有直接的操作,我建议您创建一个函数应用程序来完成这项工作。您可以直接将逻辑应用中的函数应用称为tutorial

    函数应用将接受一个日期,然后为您生成 json。然后你可以在你的逻辑应用中使用返回的 json。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-21
      • 1970-01-01
      相关资源
      最近更新 更多