Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Calculate the number of non empty custom fields (from a selection) using Smart Values

Marc Kraak
Contributor
May 29, 2023

Within our Refinement process, I would like to store the current progress of Refinement in a Custom field, so the completion of Refinement for each issue can be shown and the overall progress of refinement can be displayed as graph. I am now at the point that I am using the following Smart values

 

 

{{#if(issue.fields.'API change'.isNotEmpty())}}1{{/}}+

{{#if(issue.fields.'DIS change'.isNotEmpty())}}1{{/}}+

{#if(issue.fields.'DoD'.isNotEmpty())}}1{{/}}+

{{#if(issue.fields.'Test plan'.isNotEmpty())}}1{{/}} +

{{#if(issue.fields.'Use Case 1'.isNotEmpty())}}1{{/}}

{{/=}}

I would expect any result between empty and 5

However, I only get ++++ as a result so  

 

Later I added {{#=}} at the beginning and {{/=}} at the end, but then I get errors that it cannot calculate non-numeric values.

 

Then I added |0 to have the value 0 instead of null, like in this example 

{{#if(issue.fields.'API change'.isNotEmpty())}}1|0{{/}}

 

However, the non-empty fields are still not counted. 

Is there a way to accomplish this?

 

3 answers

1 accepted

0 votes
Answer accepted
John Funk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 30, 2023

Hey Marc,

Are all of the fields number fields? If yes, I would set the default value for each field to 0. And then bulk change all existing values to 0 if they are empty. 

Finally, and I don't know if it really makes a difference or not, but remove .fields. from the code for each field so that it is only: 

{{#=}}{{issue.API change|0}}+{{issue.DIS change|0}}+{{issue.DOD|0}}+{{issue.Test plan|0}}+{{issue.Use Case|0}}{{/}}

or use the actual id of each field like:

{{#=}}{{issue.customfield_16712|0}}+{{issue.customfield_16713|0}}+{{issue.customfield_16714|0}}+{{issue.customfield_16715|0}}+{{issue.customfield_16757|0}}{{/}}

John Funk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 3, 2023

What do you mean by default value. Can you give an exact scenario? 

John Funk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 7, 2023

Hey Marc - please reply inline to this thread so that readers can follow the conversation. 

So, in that case you could create a custom number field and then increment it by one each time one of those fields is update. And then you can add an IF condition at the end of the rule that checks if the value = 4 and then send the message or whatever needs to be done. 

Marc Kraak
Contributor
June 8, 2023

Hi John, with some help from Atlassian support I managed to create this calculation which now exactly does what I need:

{{#if(equals(customfield_10316.value,"Yes"))}}0.2{{/}}{{#if(equals(customfield_10316.value,"No"))}}0.2{{/}}{{#if(not(exists(customfield_10316.value)))}}0.0001{{/}}

+

{{#if(equals(customfield_10317.value,"Yes"))}}0.2{{/}}{{#if(equals(customfield_10317.value,"No"))}}0.2{{/}}{{#if(not(exists(customfield_10317.value)))}}0.0001{{/}}

+

{{#if(customfield_10335.isNotEmpty())}}0.2{{/}}{{#if(not(exists(customfield_10335)))}}0.0001{{/}}

+

{{#if(customfield_10168.isNotEmpty())}}0.2{{/}}{{#if(not(exists(customfield_10168)))}}0.0001{{/}}

+

{{#if(customfield_10043.isNotEmpty())}}0.2{{/}}{{#if(not(exists(customfield_10043)))}}0.0001{{/}}

 

I am using the 0.00001 value because 0 results in an empty result

I am using not exists because comparing with "None" is not possible

 

Thanks for your help!

John Funk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 8, 2023

Perfect! Thanks for updating the solution here with the code - that's fantastic!

0 votes
Marc Kraak
Contributor
June 5, 2023

Hi @John Funk , here's the complete scenario:

Within Refinement of the issues a number of fields have to filled with content. It can take hours, days of even weeks to gather all the information and put it in the right place (fields). The fields that have to be filled are "API change", "DIS Change", "DoD", "Test plan" and "Use Case". The programme manager wants to know what the progress of refinement is, for each issue, but also for all issues that aren't done. So, if of these 5 fields, 4 fields are filled, we consider the refinement for that issue 4/5 = 80% done. To store the percentage of completion I created a new customfield and if any of the 5 fields is changed I would like to calculate the number of these 5 fields that contain information, other than the default value (null/None/Empty)

0 votes
Marc Kraak
Contributor
June 1, 2023

Hi @John Funk thanks for answering. However, I don't want to add the values from those fields, but want to count the number of fields that have been filled with 'something' other than the default value. So, If 4 out of 5 fields are filled I would like to store 0,8 in the customfield Refinement Completion in order to be able to query on the progress of refinement. So basically counting the number of filled in fields.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events