Hi,
i have 8 customfields (numeric) and I want to store an average in a other customfield:
This is my json code, which works almost. First I sum all the fields and then I need to divide that with the sum of all fields that are not empty. But thats the part i dont know how to do...
{
"fields": {
"customfield_11100": "{{#=}}
({{issue.customfield_11508|0}} +
{{issue.customfield_11509|0}} +
{{issue.customfield_11511|0}} +
{{issue.customfield_11507|0}} +
{{issue.customfield_11510|0}} +
{{issue.customfield_11505|0}} +
{{issue.customfield_11506|0}} +
{{issue.customfield_11504|0}})
/
({{issue.customfield_11508.length()|0}} +
{{issue.customfield_11509.length()|0}} +
{{issue.customfield_11511.length()|0}} +
{{issue.customfield_11507.length()|0}} +
{{issue.customfield_11510.length()|0}} +
{{issue.customfield_11505.length()|0}} +
{{issue.customfield_11506.length()|0}} +
{{issue.customfield_11504.size|0}})
{{/}}"
}
}
sorry this is the solution:
{
"fields": {
"customfield_11100":
"{{#=}}
({{issue.customfield_11508|0}} +
{{issue.customfield_11509|0}} +
{{issue.customfield_11511|0}} +
{{issue.customfield_11507|0}} +
{{issue.customfield_11510|0}} +
{{issue.customfield_11505|0}} +
{{issue.customfield_11506|0}} +
{{issue.customfield_11504|0}})
/
({{#=}}
(
{{if(issue.customfield_11508,1,0)}} +
{{if(issue.customfield_11509,1,0)}} +
{{if(issue.customfield_11511,1,0)}} +
{{if(issue.customfield_11507,1,0)}} +
{{if(issue.customfield_11510,1,0)}} +
{{if(issue.customfield_11505,1,0)}} +
{{if(issue.customfield_11506,1,0)}} +
{{if(issue.customfield_11504,1,0)}}
)
{{/}})
{{/}}"
}
}
@Stefan Salzl I like your solution here, but am having some trouble
I am always returning a 0 value on my 'fieldCounts' variable. Any ideas?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Please add more details to your question (eg. screenshots of you automation rule as well as from the audit log).
This helps the community to get an overview of your current configuration and understand what you are trying to solve and how.
Best
Stefan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry @Stefan Salzl
The {{sum}} variable works.
The {{count}} variable always returns 0.
thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Could it be that your custom fields are not of type number? It´s my guess as I can see that your sum doesn´t work either. It doesn´t result a sum but concatenates to strings (0.5, 1.5).
I would recomment to check your custom fields. Furthermore you could add another log action to log the value of your custom fields.
Best
Stefan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
thanks @Stefan Salzl
This doesn't seem to be the issue. I have tried with numbers and they still always resolve as 0 whether they are NULL or not
I think the reason they looked like strings, is because I am testing with 2 records. 1 has values for both fields. The other only has values for one field. That is the result of the 2 different sums show, but they both resolve as 0 for the {{count}} variable.
For some reason the IF statement is just not picking up the value in the custom fields
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
OK.
I think I have got to the bottom of this:
This seems to be because the IF function is rounding any number below 1 (0.5 for example) to zero.
In my requirement the numbers are all between 0-1, therefore they were all returning 0.
I can confirm it works for all numbers >=1
thanks for your help @Stefan Salzl
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I could manage to calculate average with regard of amount of fields that are filled with setting variables. My automation rule looks as follows:
First I set a variable with the sum of all field´s values (that´s silmiar to your first part):
Then I create a variable for the amount of fields that are not empty. That was more the tricky part. I managed this with an if for each field: If true ( --> not null) --> add 1, else: add 0 (see screenshot):
The last part is just dividing the two variables (--> make sure to format them .asNumber as variables are stored as string by default):
Hope this was helpful and solves your problem.
Best
Stefan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.