在Azure逻辑应用程序中生成动态内容

时间:2019-07-29 07:42:53

标签: json azure azure-logic-apps

我想在天蓝色逻辑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的组合吗?在Azure逻辑应用程序中实现这样的事情?

2 个答案:

答案 0 :(得分:0)

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

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

功能应用将接受日期,然后为您生成json。然后,您可以在逻辑应用程序中使用返回的json。

答案 1 :(得分:0)

好像您正在尝试通过REST API刷新Azure Analysis Services。

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

enter image description here

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

enter image description here

现在,您创建直到循环迭代的数组,直到数组具有所需的天数。在这种情况下,您可以将其作为参数传递10。

enter image description here

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

length(variables('Dates'))

用于追加到数组变量的表达式为

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

然后只需将正文创建为

enter image description here

这里的表达式是

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"
      }
    }
  }
}