Greater Than Less Than BUG Only On Single Digit Numbers

I found an error where the following statement below breaks unless the “Property_Count_Result” = a two digit number:

(${Property_Count_Result}>${LOW} && ${Property_Count_Result}<${HIGH})

Here is an example:

LOW = 30
HIGH = 60
Property_Count_Result = 22

The solution works correctly and skips the if_v2 statement and moves to > Else > END; as the number does not fall between 30 and 60.

LOW = 30
HIGH = 60
Property_Count_Result = 40

The solution works correctly and runs through the if_v2 statement as the number falls between 30 and 60.

However, the following example BREAKS:

LOW = 30
HIGH = 60
Property_Count_Result = 5

If the number, is a single digit it will continue running through the if_v2 statement as if the number falls between 30 and 60. This issue only happens on single digit numbers. Below I have provided the code for this scenario:

,
    {
      "Command": "comment",
      "Target": "Begin Property # Algorithm",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "executeScript_Sandbox",
      "Target": "var mystring = ${Master_Property_Count}; var replaced = mystring.replace(/\\D/g, ''); return replaced",
      "Value": "Property_Count_Result",
      "Description": ""
    },
    {
      "Command": "comment",
      "Target": "Set Property # Limits",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "store",
      "Target": "30",
      "Value": "LOW",
      "Description": "Set the lowest allowed property count"
    },
    {
      "Command": "store",
      "Target": "60",
      "Value": "HIGH",
      "Description": "set the highest allowed property count"
    },
    {
      "Command": "comment",
      "Target": "If Property # Correct > SEND EMAIL",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "if_v2",
      "Target": "(${Property_Count_Result}>${LOW} && ${Property_Count_Result}<${HIGH})",
      "Value": "",
      "Description": "Greater than \"LOW\" and Less than \"HIGH\""
    },
    {
      "Command": "comment",
      "Target": "Select ALL Properties",
      "Value": "",
      "Description": ""
    },

It could be that the automatic Javascript type conversion does not work in this case? If not, then it would be comparing strings (=> alphabetic sorting!)

Solution: Use parseInt() or parseFloat()

So inside If_v2 instead of

"(${Property_Count_Result}>${LOW} && ${Property_Count_Result}<${HIGH})",

use

"(parseInt(${Property_Count_Result})>parseInt(${LOW}) && parseInt(${Property_Count_Result})<parseInt(${HIGH}))",

Basically I wrapped every string with a parseInt(…) to force the conversion to an integer.

Awesome this worked!! Thank You

Hi Ulrich,

The code was working, however, it broke for some odd reason:

(parseInt(${Property_Count_Result})>parseInt(${LOW}) && parseInt(${Property_Count_Result})<parseInt(${HIGH}))

Do I Need to include parseInt inside the below-listed sandbox script as the following values are being returned even though the text states “52 Found”:

MASTER_PROPERTY_COUNT = “2 Found”

PROPERTY_COUNT_RESULT = “2”

{
      "Command": "comment",
      "Target": "Begin Property # Algorithm",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "executeScript_Sandbox",
      "Target": "var mystring = ${Master_Property_Count}; var replaced = mystring.replace(/\\D/g, ''); return replaced",
      "Value": "Property_Count_Result",
      "Description": ""
    },
    {
      "Command": "comment",
      "Target": "Set Property # Limits",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "store",
      "Target": "30",
      "Value": "LOW",
      "Description": "Set the lowest allowed property count"
    },
    {
      "Command": "store",
      "Target": "60",
      "Value": "HIGH",
      "Description": "set the highest allowed property count"
    },
    {
      "Command": "comment",
      "Target": "If Property # Correct > SEND EMAIL",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "if_v2",
      "Target": "(parseInt(${Property_Count_Result})>parseInt(${LOW}) && parseInt(${Property_Count_Result})<parseInt(${HIGH}))",
      "Value": "",
      "Description": "Greater than \"LOW\" and Less than \"HIGH\""
    },
    {
      "Command": "comment",
      "Target": "Select ALL Properties",
      "Value": "",
      "Description": ""
    },```

Do I Need to include parseInt inside the below-listed sandbox

Yes, I think so.