2
1
0

Using Maestro 5.0.17 and the Calculation rule script:

When Amount - Decimal field (data.amount), Quantity - Currency field (data.quantity) and Shipping - Currency field (data.shipping) are entered by double-clicking from the left-side tree, this is the result using these values: 

And when the plus signs added by Maestro to the +data.quantity fields are removed, there is no change in the calculation.  However, when plus signs are added to the data.amount and data.shipping fields, such that

the calculation performs as expected:

Don't wish to tell learners to blindly add a plus in front of these fields without underlying explanation of why.  Would appreciate some guidance on what to do or admission that this is something that needs to be addressed.  Thank you.

    CommentAdd your comment...

    2 answers

    1.  
      2
      1
      0

      Hi Todd,

      The short answer is your calculation is affected by an implicit Javascript type conversion from number to text using the '+' operator, which is why the first result looks like "100" and "25" added as text, with the thousands separator and decimal appended in a currency field, ".00".

      Rule of thumb: When you see this sort of thing happening, make sure to tell Javascript precisely what types you're working with by using type constructors and math handling functions.  

      I've modified one of your lines of code to reflect this:

      return parseFloat(data.amount) * parseInt(data.quantity,10) + parseFloat(data.shipping);

      I've wrapped each component of the statement in a native Javascript function to ensure each term is appropriately typed for the operation to be performed.  Doing this also has the benefit of cleansing user input to avoid garbage in, garbage out answers.

       

      1. Unknown User (tbennethum)

        Jason, thank you for your reply. Given that I'm not a coder, I asked around, and your response is solid. My concern is for the non-coders who are using these plug-n-play functions in Maestro to handle these very issues without having to know/perform additional coding on simple calculations such as this. I suppose had I just used a decimal or other dedicated number field for quantity vs. a text field, Maestro would have recognized it as a number and the (+) issue would have been a non-issue. I'll just have to be more careful with my examples moving forward. Thanks again.

      2. Jason Hendry

        I just found this article which should help:

        Tips for working with Formulae and Text

      CommentAdd your comment...
    2.  
      1
      0
      -1

      You have identified a bug in Maestro. As you saw, references to the decimal fields were automatically prefixed with a + symbol to perform a conversion to a numeric value. This should also occur for currency fields as they also represent numeric data. This will be fixed for the next major release, along with better inline help resources in the new Code View.

      1. Tim Stewart

        The release I'm referring to is 5.1, due end of April. In the meantime please see the other workarounds described by Jason.

      CommentAdd your comment...