2

使用下面的代码作为示例(会有更多结果),我正在构建一个 if true/false 语句,它将输入为大写或小写。我不确定如何使用 tolower() 函数,该函数将强制语句的输入始终为小写。

[
    {
        "VM":  "MyVM1",
        "Success":  true,
        "PSComputerName":  "localhost",
        "PSShowComputerName":  true,
        "PSSourceJobInstanceId":  "5e18cd92-5676-4ed6-a7e4-14b0d9fea3b3"
    },
    {
        "VM":  "MyVM2",
        "Success":  true,
        "PSComputerName":  "localhost",
        "PSShowComputerName":  true,
        "PSSourceJobInstanceId":  "5e18cd92-5676-4ed6-a7e4-14b0d9fea3b3"
    }
]

我的逻辑应用流程: 在此处输入图像描述

我首选的逻辑应用流程更改: 流动

如您所见,我尝试使用以下条件:

@contains(tolower(items('For_each')['VM'], 'myvm1'))

但是,在运行逻辑应用程序时,我会看到以下错误输出:

无效的模板。无法在“1”行和“2179”列处理操作“条件”的模板语言表达式:“模板语言函数“tolower”需要一个参数:要转换为小写的字符串。该函数是使用“2”参数调用的。请参阅https://aka.ms/logicexpressions#toLower了解使用详情。

https://docs.microsoft.com/en-us/azure/logic-apps/logic-apps-workflow-definition-language

我查看了文档,但遗憾的是我对它的理解还不够,无法知道如何编辑此查询。任何帮助都会非常感激

4

2 回答 2

3

所以......错误是正确的。你现在的表情

@contains(tolower(items('For_each')['VM'], 'myvm1'))

将两个参数传递给 tolower()

@contains(tolower( items('For_each')['VM'], 'myvm1' ))

items('For_each')['VM'] --and-- 'myvm1'

也许你真的想要

@contains(tolower(items('For_each')['VM']), 'myvm1')

于 2018-02-28T18:12:57.047 回答
1

@John-305 的答案是正确的。你的陈述有括号问题。正确的说法是:

“@contains(tolower(items('For_each')['VM']), 'myvm1')”

试试这个逻辑应用以供参考:

{
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "actions": {
            "For_each": {
                "actions": {
                    "Condition": {
                        "actions": {
                            "Append_to_array_variable": {
                                "inputs": {
                                    "name": "result",
                                    "value": "@items('For_each')"
                                },
                                "runAfter": {},
                                "type": "AppendToArrayVariable"
                            }
                        },
                        "expression": "@contains(tolower(items('For_each')['VM']), 'myvm1')",
                        "runAfter": {},
                        "type": "If"
                    }
                },
                "foreach": "@body('Parse_JSON')",
                "runAfter": {
                    "Initialize_variable": [
                        "Succeeded"
                    ]
                },
                "type": "Foreach"
            },
            "Initialize_variable": {
                "inputs": {
                    "variables": [
                        {
                            "name": "result",
                            "type": "Array"
                        }
                    ]
                },
                "runAfter": {
                    "Parse_JSON": [
                        "Succeeded"
                    ]
                },
                "type": "InitializeVariable"
            },
            "Parse_JSON": {
                "inputs": {
                    "content": [
                        {
                            "PSComputerName": "localhost",
                            "PSShowComputerName": true,
                            "PSSourceJobInstanceId": "5e18cd92-5676-4ed6-a7e4-14b0d9fea3b3",
                            "Success": true,
                            "VM": "MyVM1"
                        },
                        {
                            "PSComputerName": "localhost",
                            "PSShowComputerName": true,
                            "PSSourceJobInstanceId": "5e18cd92-5676-4ed6-a7e4-14b0d9fea3b3",
                            "Success": true,
                            "VM": "MyVM2"
                        }
                    ],
                    "schema": {
                        "items": {
                            "properties": {
                                "PSComputerName": {
                                    "type": "string"
                                },
                                "PSShowComputerName": {
                                    "type": "boolean"
                                },
                                "PSSourceJobInstanceId": {
                                    "type": "string"
                                },
                                "Success": {
                                    "type": "boolean"
                                },
                                "VM": {
                                    "type": "string"
                                }
                            },
                            "required": [
                                "VM",
                                "Success",
                                "PSComputerName",
                                "PSShowComputerName",
                                "PSSourceJobInstanceId"
                            ],
                            "type": "object"
                        },
                        "type": "array"
                    }
                },
                "runAfter": {},
                "type": "ParseJson"
            },
            "Response": {
                "inputs": {
                    "body": "@variables('result')",
                    "statusCode": 200
                },
                "runAfter": {
                    "For_each": [
                        "Succeeded"
                    ]
                },
                "type": "Response"
            }
        },
        "contentVersion": "1.0.0.0",
        "outputs": {},
        "parameters": {},
        "triggers": {
            "manual": {
                "inputs": {
                    "schema": {}
                },
                "kind": "Http",
                "type": "Request"
            }
        }
    }
}
于 2018-03-01T09:22:11.130 回答