Warm tip: This article is reproduced from serverfault.com, please click

using a variable in an equals expression

发布于 2020-12-01 10:44:42

I'm trying to do something very simple in Logic Apps: I want to check whether a variable equals a given string, I'm using this expression but it always gives me False

{
    "name": "task_name",
    "type": "string",
    "value": "MyTask"
}  


{
  "name": "equalsVar",
  type": "Boolean",
  "value": "@equals(variables('task_name'),'MyTask')"
}

equalsVar is always False, please explain where I'm doing something wrong

Questioner
michiel Thai
Viewed
0
Frank Gong 2020-12-01 19:34:44

There seems to be no problem with this expression, please check if there is a problem with your azure logic app design.

You can refer to this logic app code in logic app code view:

{
    "definition": {
        "$schema": "<your-schema>",
        "actions": {
            "Initialize_variable": {
                "inputs": {
                    "variables": [
                        {
                            "name": "task_name",
                            "type": "string",
                            "value": "MyTask"
                        }
                    ]
                },
                "runAfter": {},
                "type": "InitializeVariable"
            },
            "Initialize_variable_2": {
                "inputs": {
                    "variables": [
                        {
                            "name": "equalsVar",
                            "type": "Boolean",
                            "value": "@equals(variables('task_name'),'MyTask')"
                        }
                    ]
                },
                "runAfter": {
                    "Initialize_variable": [
                        "Succeeded"
                    ]
                },
                "type": "InitializeVariable"
            }
        },
        "contentVersion": "1.0.0.0",
        "outputs": {},
        "parameters": {},
        "triggers": {
            "manual": {
                "inputs": {
                    "schema": {}
                },
                "kind": "Http",
                "type": "Request"
            }
        }
    },
    "parameters": {}
}

Or you can refer to this design in logic app designer:

enter image description here

enter image description here