Search code examples
azureazure-logic-appstolower

How to use Logic App tolower() function


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 logic app flow: enter image description here

My preferred logic app flow alteration: flow

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


Solution

  • 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')