Forums

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

Count the custom field value on subtask and display on parent ticket custom field

Lakshmi CH
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 11, 2023

Hi Team,

We have two fields, Agency Count (number field) and Agency (Check box with Yes and No). 

The requirement is :

Count the number of "Yes" values in the "Agency" field that appear in the subtasks and then display the total in the parent field  "Agency Count." 

Is it possible with Scriptrunner or JMWE apps ?

2 answers

1 accepted

2 votes
Answer accepted
Ram Kumar Aravindakshan _Adaptavist_
Community Champion
August 12, 2023

Hi @Lakshmi CH

To answer your question, ScriptRunner can do this.

For your requirement, it would be best to use a Custom Scripted Field for the Agency Count.

Please ensure you are using the latest release of ScriptRunner so you can use the HAPI feature to simplify your coding.

Below is a sample working code for your reference:-

def count = [] as ArrayList

issue.subTaskObjects.each {

//Rename this custom field
def sampleCheckBoxValue = it.getCustomFieldValue('Sample Checkbox').toString()

if (sampleCheckBoxValue == '[Yes]') {
count << 1
}
}
count.sum()

Please note that the sample working code above is not 100% exact to your environment. Hence, you will need to make the required modifications.

Below is a screenshot of the Scripted Field configuration:-

scripted_field_config.png

Below are a couple of test screenshots for your reference:-

1. For the first test case, I created a Story and added 4 Sub-tasks to it. For the first 3 Sub-tasks, I selected the option Yes in the checkbox, and for the last Sub-task, I selected the option No.

As expected, the Total field (Scripted Field) in the Story issue returns the value 3 since 3 of the 3 Sub-tasks have been set to Yes.

test1.pngtest2.pngtest3.pngtest4.pngtest5.png

2. I will add the 5th Sub-task and set the checkbox to Yes for the next test case. As expected, the Total field in the Story issue is updated to 4. Below are the screenshots for your reference:-

test6.pngtest7.png

I hope this helps to solve your question. :-)

Thank you and Kind regards,
Ram

Lakshmi CH
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 14, 2023

Thank you so much, Ram! @Ram Kumar Aravindakshan _Adaptavist_ . You are the best! This is my exact requirement.

0 votes
David Fischer
Community Champion
August 11, 2023

Hi @Lakshmi CH 

The easiest is to create either a JMCF Calculated Number field or the equivalent ScriptRunner scripted field. The nice thing about calculated fields is that their value is calculated on the fly when the issue is displayed. Otherwise, changing the value of a regular Number field whenever a sub-task is updated, using a JMWE event-based action or equivalent in ScriptRunner is much harder, because you need to update the parent Agency count field not only when a checkbox is modified, but also when you add or remove a sub-task.

Suggest an answer

Log in or Sign up to answer