Using Automation, I'm trying to do a very simple (seemingly) calculation but not having much success. Actually - I did get it to work, but still getting the answers to the questions below will greatly increase my understanding of this functionality
Here is what I'm trying to accomplish.
- We have a numeric custom field in our issue that is intended to contain the number of hours to complete a task. The field has no default and therefore if not filled in, it says "None" on the screen and is empty.
- I want to calculate the cost associated with the task by multiplying the hours times a constant rate. Ultimately I am going to update another field with the cost, but for now just using the log output function to debug this
Here were my attempts
- I wanted to do this the hard way first, so I tried using an IF statement using smartvalues. First I had issues referencing the issue field directly with additions like isempty so I assigned it to a new variable, and that worked fine (???). So now it was correctly detecting empty vs not empty... And then I assigned the smartvalue below to a new variable...
- {{#=}} IF({{hours.isEmpty()}} == true, 0, {{hours}} * 53 ) {{/}}
- I get this errror "Error rendering smart-values when executing this rule: Unknown unary operator '*' at position 22: IF(true == true, 0, * 53 )".
- I understand why (because {{hours}} is truly empty), but then how could I ever solve this?? I'm sure there is a simple solution, but I'm coming up empty.
- Failing the above I decided to try a normal IF ELSE block in the Automation. Basically I have an if/else block and check if the issue value is empty or not. If it is empty I assign 0 to a new variable: "hourscost". In the else block I assign the calculated hours issue value * 53.
- I have log entries immediately after to make sure the value is in fact stored properly in {{hourscost}}. Everything is fine there...
- Falling out of the if/else block my next statement is the final log entry to again display the value of {{hourscost}} but outside of the if/else block the value is blank.
- Update: I added an assignment for the same hourscost variable prior to entering the if/else block. After doing this the value was correctly updated and shows outside the block at the end. I didn't expect this behavior. Is the scoping of variables intentionally separate inside the if/else structure.
Bonus question
- Is there a way to create some type of project level constant (that I can reference from smartvalues) for the rate value above instead of embedding it in the automation?