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 ?
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:-
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.
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:-
I hope this helps to solve your question. :-)
Thank you and Kind regards,
Ram
Thank you so much, Ram! @Ram Kumar Aravindakshan _Adaptavist_ . You are the best! This is my exact requirement.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
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.