如何使用 Logic App tolower() 函数
How to use Logic App tolower() function
使用下面的代码作为示例(会有更多的结果),我正在构建一个 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. Unable to process template language expressions for
action 'Condition' at line '1' and column '2179': 'The template
language function 'tolower' expects one parameter: the string to
convert to lower casing. The function was invoked with '2' parameters.
Please see https://aka.ms/logicexpressions#toLower for usage
details.'.
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'] --and-- '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"
}
}
}
}
使用下面的代码作为示例(会有更多的结果),我正在构建一个 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. Unable to process template language expressions for action 'Condition' at line '1' and column '2179': 'The template language function 'tolower' expects one parameter: the string to convert to lower casing. The function was invoked with '2' parameters. Please see https://aka.ms/logicexpressions#toLower for usage details.'.
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'] --and-- '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"
}
}
}
}