Bad expression in post-function "Copy a parsed text to a field"

Issue #813 resolved
Jens Kisters created an issue

Hello, i am trying to create a workflow validator that checks if the sum of a bunch of number fields equals the entry in another number field.

I had an error there and then decided to debug this by creating a post function that writes a comment with the outcome of the formula:

(toNumber({11403}) + toNumber({11406}) + toNumber({11404}) + toNumber({11405}) + toNumber({11409}) + toNumber({11410}) + toNumber({11407}) + toNumber({11408})) + " = " + toNumber({11421})

I wrapped the fields in "toNumber" because most of them will be empty. I also tried toNumber(field1+field2+...) but that doesnt work either.

The validation i try to debug is: toNumber({11403}+{11406}+{11404}+{11405}+{11409}+{11410}+{11407}+{11408}) = toNumber({11421})

How can i make this validation work?

Thanks a lot Jens

Comments (5)

  1. Fidel Castro Armario repo owner

    Hi @jkisters,

    Field codes with with % (i.e., format {nnnnn}) represent a string value, while field codes without % represent a numeric value.

    We use function toNumber() in order to obtain a numeric value from a string. In this case you don't need to use this function, since the fields are already numeric.

    You should use the following boolean expression in your validation:

    {11403} + {11406} + {11404} + {11405} + {11409} + {11410} + {11407} + {11408} = {11421}
    

    I'm assuming that all the fields in the formula are numeric fields.

  2. Jens Kisters reporter

    Good Morning,

    that was my first try but i kept getting an error like this "null value at left hand side operand in arithmetic subtraction", i also got this error for the right hand side. But i can't reproduce this now, maybe this was just an cloning issue that was fixed by ticking the appropriate checkbox.

    Thank you!

  3. Jens Kisters reporter
    • changed status to open

    Oh i managed to reproduce it:

    com.atlassian.jira.exception.CreateException: ERROR IN BOOLEAN EXPRESSION "{11403}+{11406}+{11404}+{11405}+{11409}+{11410}+{11407}+{11408} = {11421}" : Error: null value at left hand side operand in arithmetic sum operation.

    I had all number fields on the left hand side empty. can i handle this case in the formula or do i have to make an separate empty check for alle the fields and run it before i run this validation (on create)

  4. Fidel Castro Armario repo owner

    Hi @jkisters,

    Use the following alternative expression:

    sum([{11403}, {11406}, {11404}, {11405}, {11409}, {11410}, {11407}, {11408}]) = {11421}
    
  5. Fidel Castro Armario repo owner

    I close the issue, please reopen it if you find that provided solution is not satisfactory.

  6. Log in to comment