1 Reply Latest reply: Aug 23, 2013 11:23 AM by Daniel Atwood RSS

    How to convert string to decimal in data association function?

    JoeA

      In a BPM Script component, how in the Data Association can I use an expression to convert an argument from String to Decimal?  I have a Process argument named percentage which is a string.  I need to set the value of a data object called signed to either "Y" or "N" based on the percentage being greater than 0.4.  Something like this:

       

      (percentage > 0.4) ? "Y" : "N"

       

      The problem here is that percentage is a string, so must be converted to a decimal value before the compare will work.  I cannot find a function that allows that.  I need something like parseDecimal(percentage), but the Expression Builder does not offer that for a string using a Simple Expression.

       

      If it cannot be converted, is there another way to do this?

        • 1. Re: How to convert string to decimal in data association function?
          Daniel Atwood

          Guessing you figured this out on your own, but if you wanted to use a Script activity one way to do what you want is when you're creating your data associations drag the "Expression" icon in the middle and double click the icon in the middle you just added:

          1. Get out of the Simple expression mode and into the XPath expression mode by clicking the dropdown in the upper left corner -> click "XPath Exp".
          2. In the Functions dropdown on the right, click "Conversion Functions" -> click "number" and then insert it into the expression.
          3. In the Variables list, select your string variable and insert it into the number function so that it looks something like this:  number(bpmn:getDataObject('myStringVariable'))
          4. Click OK
          5. Click your expression icon in the middle and drag it over your decimal variable.

           

          To have it evaluate and return a Boolean expression in your Script activity, add a Boolean process variable and add an XPath expression as described above except have the logic be this:  number(bpmn:getDataObject('myStringVariable')) > .4  (the "greater than" shown above is added to the expression by clicking "Logical Functions" from the functions dropdown).  Click OK and drag your expression icon over your Boolean variable.

           

          Dan