使用下面的代码作为示例(会有更多的结果),我正在构造一个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'))
但是,当运行逻辑应用程序时,我会看到以下错误输出:
InvalidTemplate。无法处理第1行和第2179行的“条件”操作的模板语言表达式:'模板语言函数'tolower'需要一个参数:要转换为下限的字符串。使用'2'参数调用该函数。有关使用详情,请参阅https://aka.ms/logicexpressions#toLower。'。
https://docs.microsoft.com/en-us/azure/logic-apps/logic-apps-workflow-definition-language
我查看了文档,但遗憾的是我不太了解如何编辑此查询。任何帮助都会非常感激
所以...错误是正确的。你当前的表达
@contains(tolower(items('For_each')['VM'],'myvm1'))
将两个参数传递给tolower()
@contains(tolower(items('For_each')['VM'],'myvm1'))
items('For_each')['VM'] - 和 - 'myvm1'
也许你真的想要
@contains(tolower(items('For_each')['VM']),'myvm1')
来自@ 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"
}
}
}
}