locked
@Equals Error RRS feed

  • Question

  • Hi,

    I don't know why these expressions are difficult but I am stuck on this:

    I have a Set Variable where I am doing this:

    @equals(substring(variables('StoredProc'),10,17),'hourlygas')

    for the file name:

    e717c80e-7757-4c22-a630-3bbe3e7d6444_scada.usp_HourlyGas_TvpMerge.json

    I essentially want to set Variable to this if "hourlygas" is in the filename and I keep getting an error. 

    Expression of type: 'Bool' does not match the field: 'value


    Can you please assist?
    Thanks
    Mike


    Mike Kiser


    • Edited by EMKISER Monday, July 1, 2019 9:46 PM
    Monday, July 1, 2019 9:34 PM

Answers

  • Hello again Mike Kiser.   The reason you are having difficulty here, is that 'equals' is case-sensitive.  An equals condition checks each character for an exact match.  The H in HourlyGast_Tvp is capitalized, where in your expression, it is lower case.  Try using a string function to change to all lower or all uppercase before comparing.

    Alternatively you can use the 'indexof' string function to determine case-insensitive whether hourlygas is in your filename.  When 'hourlygas' is Not contained in your filename, 'indexof' returns a value of -1.  Otherwise, the index of the first letter is returned.

    Monday, July 1, 2019 10:33 PM
  • This error message means that the data type of the output of your expression does not match the data type of your variable.  the equals function returns a boolean (true / false).  Please check the data type of your variable.  If your variable is of type string, you can wrap your expression inside @string() to look like:
    @string(equals(substring(variables('StoredProc'),10,17),'hourlygas'))
    Monday, July 1, 2019 10:44 PM
  • Awesome Martin!

    Let me try that...I understand now...thanks for explaining...and my variable is of type "STRING" ....I really appreciate your quick response...

    Thanks!
    Mike


    Mike Kiser



    • Edited by EMKISER Monday, July 1, 2019 11:14 PM
    • Marked as answer by EMKISER Wednesday, July 3, 2019 3:36 PM
    Monday, July 1, 2019 11:13 PM
  • Hi Martin,

    I just tried and got the below error:

    @string(equals(substring(variables('StoredProc'),10,17),'hourlygas'))

    Also, here is the variable 'StoredProc' in the debugger

    name": "StoredProc", "value": "scada.usp_HourlyGas_TvpMerge"

    Error:
    { "errorCode": "InvalidTemplate", "message": "The function 'substring' parameters are out of range: 'start index' and 'length' must be non-negative integers and their sum must be no larger than the length of the string.", "failureType": "UserError", "target": "DebugHourly" }

    Any ideas?

    Thanks,
    Mike


    Mike Kiser


    • Edited by EMKISER Monday, July 1, 2019 11:49 PM
    • Marked as answer by EMKISER Wednesday, July 3, 2019 3:36 PM
    Monday, July 1, 2019 11:22 PM
  • Hi

    I just tried 

    @string(equals(substring(variables('StoredProc'),11,9),'HourlyGas'))

    in my SetVariable

    and got this error:

    Expression of type: 'String' does not match the field: 'expression'

    What exactly does a True in a SetVariable do?

    Thanks again ...I have been working on this diligently...

    Mike


    Mike Kiser

    • Marked as answer by EMKISER Wednesday, July 3, 2019 3:36 PM
    Tuesday, July 2, 2019 1:04 AM
  • If you are getting 'out of range' errors, and the value of 'StoredProc' is greater than those numbers, I must speculate that the comparison is being executed before the completion of setting the value of 'StoredProc' .  To ensure that 'StoredProc' finishes setting its value before doing the comparison, use a dependency line to connect the two activities, from 'StoredProc' set Variable to the comparison activity.
    • Marked as answer by EMKISER Wednesday, July 3, 2019 3:36 PM
    Tuesday, July 2, 2019 6:40 PM
  • I am somewhat confused.  I used string variables to set
    @string(equals(substring(variables('StoredProc'),11,9),'HourlyGas'))
    scada.usp_HourlyGas_TvpMergewithout any problem.  Did you swap types again?

    By "What exactly does a True in a SetVariable do?" are you asking for a use-case?  One use-case would be to break down a long and complex nested logic into smaller steps, making troubleshooting easier.  "True" is the human-friendly designation of the boolean 'True' value.

    What do you want to do with the result of the comparison?

    Personally, I would write it differently, like:

    @if( greaterOrEquals( indexof( variables('StoredProc'), 'HourlyGas'), 10 ) , 'Found_the_word', 'Did_not_find')

    This allows you to directly specify what you want returned as the result.  It also is case-insensitive (should you want that).

    • Marked as answer by EMKISER Wednesday, July 3, 2019 3:36 PM
    Tuesday, July 2, 2019 7:05 PM

All replies

  • Hello again Mike Kiser.   The reason you are having difficulty here, is that 'equals' is case-sensitive.  An equals condition checks each character for an exact match.  The H in HourlyGast_Tvp is capitalized, where in your expression, it is lower case.  Try using a string function to change to all lower or all uppercase before comparing.

    Alternatively you can use the 'indexof' string function to determine case-insensitive whether hourlygas is in your filename.  When 'hourlygas' is Not contained in your filename, 'indexof' returns a value of -1.  Otherwise, the index of the first letter is returned.

    Monday, July 1, 2019 10:33 PM
  • This error message means that the data type of the output of your expression does not match the data type of your variable.  the equals function returns a boolean (true / false).  Please check the data type of your variable.  If your variable is of type string, you can wrap your expression inside @string() to look like:
    @string(equals(substring(variables('StoredProc'),10,17),'hourlygas'))
    Monday, July 1, 2019 10:44 PM
  • Awesome Martin!

    Let me try that...I understand now...thanks for explaining...and my variable is of type "STRING" ....I really appreciate your quick response...

    Thanks!
    Mike


    Mike Kiser



    • Edited by EMKISER Monday, July 1, 2019 11:14 PM
    • Marked as answer by EMKISER Wednesday, July 3, 2019 3:36 PM
    Monday, July 1, 2019 11:13 PM
  • Hi Martin,

    I just tried and got the below error:

    @string(equals(substring(variables('StoredProc'),10,17),'hourlygas'))

    Also, here is the variable 'StoredProc' in the debugger

    name": "StoredProc", "value": "scada.usp_HourlyGas_TvpMerge"

    Error:
    { "errorCode": "InvalidTemplate", "message": "The function 'substring' parameters are out of range: 'start index' and 'length' must be non-negative integers and their sum must be no larger than the length of the string.", "failureType": "UserError", "target": "DebugHourly" }

    Any ideas?

    Thanks,
    Mike


    Mike Kiser


    • Edited by EMKISER Monday, July 1, 2019 11:49 PM
    • Marked as answer by EMKISER Wednesday, July 3, 2019 3:36 PM
    Monday, July 1, 2019 11:22 PM
  • Hi

    I just tried 

    @string(equals(substring(variables('StoredProc'),11,9),'HourlyGas'))

    in my SetVariable

    and got this error:

    Expression of type: 'String' does not match the field: 'expression'

    What exactly does a True in a SetVariable do?

    Thanks again ...I have been working on this diligently...

    Mike


    Mike Kiser

    • Marked as answer by EMKISER Wednesday, July 3, 2019 3:36 PM
    Tuesday, July 2, 2019 1:04 AM
  • If you are getting 'out of range' errors, and the value of 'StoredProc' is greater than those numbers, I must speculate that the comparison is being executed before the completion of setting the value of 'StoredProc' .  To ensure that 'StoredProc' finishes setting its value before doing the comparison, use a dependency line to connect the two activities, from 'StoredProc' set Variable to the comparison activity.
    • Marked as answer by EMKISER Wednesday, July 3, 2019 3:36 PM
    Tuesday, July 2, 2019 6:40 PM
  • I am somewhat confused.  I used string variables to set
    @string(equals(substring(variables('StoredProc'),11,9),'HourlyGas'))
    scada.usp_HourlyGas_TvpMergewithout any problem.  Did you swap types again?

    By "What exactly does a True in a SetVariable do?" are you asking for a use-case?  One use-case would be to break down a long and complex nested logic into smaller steps, making troubleshooting easier.  "True" is the human-friendly designation of the boolean 'True' value.

    What do you want to do with the result of the comparison?

    Personally, I would write it differently, like:

    @if( greaterOrEquals( indexof( variables('StoredProc'), 'HourlyGas'), 10 ) , 'Found_the_word', 'Did_not_find')

    This allows you to directly specify what you want returned as the result.  It also is case-insensitive (should you want that).

    • Marked as answer by EMKISER Wednesday, July 3, 2019 3:36 PM
    Tuesday, July 2, 2019 7:05 PM