I have an OKR project in our Jira Cloud, that requires the calculation of some values. I have created Initial Value, Current Value and Target Value, and I'm using smart values in Jira Automation to calculate percentage of completion in a Score field, whenever one of the value fields changes. These are all Number fields visible on the edit screen.
The calculation was given to me as (Current Value - Initial Value) / (Target Value - Initial Value) * 100 (for the percentage).
I first attempted this as
{{#=}} {{issue.Current Value} - {issue.Initial Value}} / {{issue.Target Value} - {issue.Initial Value}} * 100 {{/}}
error: Unknown unary operator * at character position 14: 3.0 - 2.0 / * 100
and then as
{{#=}} {{issue.Current Value.subtract(issue.Initial Value)}} / {{issue.Target Value.subtract(issue.Initial Value)}} * 100 {{/}}
error: error: Unknown unary operator / at character position 1: / * 100
without success (current value 3, initial value 2, target value 4)
@Bill Sheboy @Daniel Eads can perhaps help here I hope
Hi Steven
Not sure if it is a typo but your example is missing some curly braces
{{#=}} {{issue.Current Value} - {issue.Initial Value}} / {{issue.Target Value} - {issue.Initial Value}} * 100 {{/}}
and gets the error Unknown unary operator * at character position 14: 3.0 - 2.0 / * 100
example of working
{{#=}} {{issue.Current Value}} - {{issue.Initial Value}} / {{issue.Target Value}} - {{issue.Initial Value}} * 100 {{/}}
Unable to see subtract here https://support.atlassian.com/cloud-automation/docs/jira-smart-values-math-expressions/#Mathematical-operators so would be minus
{{#=}} {{issue.Current Value.minus(issue.Initial Value)}} / {{issue.Target Value.minus(issue.Initial Value)}} * 100 {{/}}
🤦 d'oh. I can tell you that with the minus instead of subtract, it is indeed working. ✅
Not sure how I could have missed that. As for the first (wrong) code, yes, i'm missing curly brackets, but the formula is wrong and I think its probably something to do with order of operations.
Thanks for the answer! Hard to see the wood for the trees sometimes.
One thing to note: It is possible to end up with a division by zero, but Jira doesnt throw an error in the Score field, just a number thats in the minus and very wrong. The chances of getting it are slim anyway.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Steven
Yes, I wasn't sure about the math on the first example as I would presume it would follow math order of operations
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Given the possibility of a divide-by-zero in your formula, or a zero numerator, you may want to add some condition checks, and null-handling for those cases. For example on the null-handling, this would return 0 when the field is null.
{{issue.myField|0}}
There is an edge-case if a Jira field has ever had a value, and then been cleared with the UI or REST API. That is technically "empty" and no longer null, and has been shown to cause problems with JQL...and so probably impacts smart values also.
Kind regards,
Bill
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
{{#=}} {{issue.Current Value.minus(issue.Initial Value|0)}} / {{issue.Target Value.minus(issue.Initial Value|0)}} * 100 {{/}}
There is indeed a chance of division by zero. 40 / 50 / 40 would do that.
For the null handling would this be correct? It doesnt seem to work if I clear the Score field and then try to trigger another division by zero but thats ok. I get a negative number.
What about when the Current Value or Target Value is null? And I think i only need to have the |0 on the 2nd initial value as thats that the one that is doing the divide.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am experiencing a similar issue. Checked my syntax (and curly braces), but still getting the same error.
Unknown unary operator * at character position 1
My JSON is the following:
{
"fields": {
"Opportunity": {{#=}} {{issue.Total Revenue}} * {{issue.Addressable GGR}} {{/}}
}
}
I am trying to update the "Opportunity" field, multiplying the "Total Revenue" and "Addressable GGR" fields.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Francesco Borgosano -- Welcome to the Atlassian Community!
That error can occur when you have the incorrect smart value for the field, as it becomes an empty/null value in the expression.
Smart values are name, spacing, and case-sensitive. Please use this how-to article to confirm the smart values for your fields.
Basically, you identify an example issue with your fields and call the REST API with a browser, and then search for your field to find the exact smart value to use.
https://support.atlassian.com/cloud-automation/docs/find-the-smart-value-for-a-field/
Kind regards,
Bill
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Bill Sheboy,
thank you that was very helpful. I managed to extract all the fields from my Issue using the REST API. And there was indeed a mismatch in names. I am now trying to use the custom field to simplify my string. And, I am getting a different error.
This is my new JSON:
{
"fields": {
"customfield_10124" : "{{#=}} {{customfield_10129}} * {{customfield_10132}} {{/}}
}
}
ERROR:
Error while parsing additional fields. Not valid JSON.
Is there an API to test a JSON update? How can I validate the format?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
There are a few tools to do that, which you can search for online. As much of the syntax is based on automation rules, you may note find a perfect validator.
One simple way to validate is to use a basic text editor which shows/highlights the matching quotes, brackets, etc. the expression. For example, the free app Notepad++ can do this.
Doing that, I found you have a stray double-quotation mark before the math operator. So you can either add another one at the end, or try removing the one before {{#=}}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks, @Bill Sheboy!
I have used Atom to check the format, and as you correctly pointed out there was a double quotation missing.
My first Automation works! Thanks again for your help.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
{{#=}}100-{{issue.customfield_1112}}-{{issue.customfield_1113}}*360/60*5{{/}} it isn't correct where is my problem could you please help me about this? i want write smart value in automation in jira
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.