locked
Invalid expresion in logical functions with variables RRS feed

  • Question

  • I got invalid expression error when i try to use the expression

    @greater(variables('x'), variables('y'))

    i got the same error with less, equals and the others logical functions.

    Thursday, January 17, 2019 2:42 PM

Answers

  • Hi Jyeros,

    Sorry that is confusing -- we're working on making variables more user friendly and add additional documentation around this. To get your scenario working, there are a couple things to note:

    1) Until Activity

    For your expression language, you need to convert the variables to "int" before comparisons. Currently, our only allowed variable types are string, array, boolean. To use the "greater" comparison, you need to convert to int first. Strings won't compare correctly.

    

    2) Incrementing your variable within a container

    An important caveat: variables cannot reference themselves. Unlike code, x=x+1 is not allowed. Instead, you need to create a new variable, say "z" as your temp variable. Thus the process is:

    do until:

        z = x

        x = z+1

    -------------------------------

    --------------------

    The result of my loop is that x increments in value:


    Wednesday, January 23, 2019 8:04 PM

All replies

  • @jyeros Thanks for your feedback. Could you please confirm the activities in your pipeline so that I can understand your issue better and help you further in this issue.
    Friday, January 18, 2019 10:13 AM
  • It is the code of my pipeline:

    {
    "name": "pipeline1",
    "properties": {
    "activities": [
    {
    "name": "Until1",
    "type": "Until",
    "typeProperties": {
    "expression": {
    "value": "@equals(variables('x'),variables('y'))",
    "type": "Expression"
    },
    "activities": [
    {
    "name": "Wait1",
    "type": "Wait",
    "typeProperties": {
    "waitTimeInSeconds": 1
    }
    },
    {
    "name": "Set Variable1",
    "type": "SetVariable",
    "dependsOn": [
    {
    "activity": "Wait1",
    "dependencyConditions": [
    "Succeeded"
    ]
    }
    ],
    "typeProperties": {
    "variableName": "x",
    "value": {
    "value": "@string(add(int(variables('x')), 1))",
    "type": "Expression"
    }
    }
    }
    ],
    "timeout": "7.00:00:00"
    }
    }
    ],
    "variables": {
    "x": {
    "type": "String",
    "defaultValue": "1"
    },
    "y": {
    "type": "String",
    "defaultValue": "10"
    }
    }
    }
    }

    And i got the following error

    

    But like @hammondan wrote at Scope of variables Question the problems happend when

    I use the Set Activity in the UntilActivity, if I delete the Set Activity the pipeline

    work fine and if I try to execute it I got the following error

    Friday, January 18, 2019 2:25 PM
  • Sorry for the delay in response. 

    Thanks @jyeros for sharing the screenshots and details. I have tried the same thing and facing the same issue.

    I am checking internally with other teams to get it resolved. Will keep you posted.

    Wednesday, January 23, 2019 10:46 AM
  • Hi Jyeros,

    Sorry that is confusing -- we're working on making variables more user friendly and add additional documentation around this. To get your scenario working, there are a couple things to note:

    1) Until Activity

    For your expression language, you need to convert the variables to "int" before comparisons. Currently, our only allowed variable types are string, array, boolean. To use the "greater" comparison, you need to convert to int first. Strings won't compare correctly.

    

    2) Incrementing your variable within a container

    An important caveat: variables cannot reference themselves. Unlike code, x=x+1 is not allowed. Instead, you need to create a new variable, say "z" as your temp variable. Thus the process is:

    do until:

        z = x

        x = z+1

    -------------------------------

    --------------------

    The result of my loop is that x increments in value:


    Wednesday, January 23, 2019 8:04 PM
  • Hi Jyeros,

    Just checking in to see if the above answer helped. If this answers your query, do click “Mark as Answer” and Up-Vote for the same. And, if you have any further query do let us know. 

    Monday, January 28, 2019 6:40 AM
  • Thanks, it works. And thanks for show the problem at log when i try to do it.
    Monday, January 28, 2019 10:46 PM