Using the below code as a sample (there would be way more results), I am constructing an if true/false statement that will have the input as either upper or lower case. I am unsure how to utilise the tolower() function that will force the input to always be lower case for the statement.
[
{
"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"
}
]
My preferred logic app flow alteration:
As you can see, I have tried using the condition as follows:
@contains(tolower(items('For_each')['VM'], 'myvm1'))
However I am presented with the following error output when the logic app is run:
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://learn.microsoft.com/en-us/azure/logic-apps/logic-apps-workflow-definition-language
I have looked at the documentation, but sadly I don't understand it enough to know how to edit this query. Any help would be greatly apprec
CodePudding user response:
So...the error is correct. Your current expression
@contains(tolower(items('For_each')['VM'], 'myvm1'))
is passing two parameters to tolower()
@contains(tolower(items('For_each')['VM'], 'myvm1'))
items('For_each')['VM'] --and-- 'myvm1'
Maybe you really want
@contains(tolower(items('For_each')['VM']), 'myvm1')
CodePudding user response:
The answer from @John-305 is correct. You have parenthesis issue with you statement. The Correct statement is:
"@contains(tolower(items('For_each')['VM']), 'myvm1')"
Try this logic app for reference:
{
"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"
}
}
}
}