Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Set parent issue custom field value depending on sub-tasks's values

Deleted user Sep 24, 2018

Hi

I'm currently trying to set a parent issue's custom field (single choice select list) based on the values for the same custom field in its sub-tasks.

It's a simple select list with as answers 'Yes', 'No', and 'Unspecified'. The field is used to see if there is an impact for capacity planning. This means that if one of the sub-tasks has 'Yes' as a value, the parent issue should automatically be 'Yes' as well, because there is an impact.

If there are no 'Yes' answers found in the sub-tasks, it may still be unspecified, so the parent issue shouldn't say no just yet. If there are no 'Unspecified' values found either, then we can conclude that 'No' should be set for the impact.

I had created the following script and added it as an initialiser in ScriptRunner Behaviours and mapped it to the issue type and correct project. However, with the following code, Jira seems to get stuck in loading and crashes (or at least is unaccessible for a couple of minutes). I'm pretty new to groovy scripting in Jira, so I'm probably using wrong things mixed together.

Thanks in advance!

------------------------------CODE-----------------------------------------

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.ComponentManager

def cfName = "Performance Reporting impact"
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def customField = customFieldManager.getCustomFieldObjectByName(cfName)

boolean val = false
boolean unspecified = false

def subtasks = underlyingIssue.getSubTaskObjects()

if(subtasks == null)
 return

if(customField == null)
 return

for(subtask in subtasks)
{
    if(subtask.getCustomFieldValue(customField) == 'Yes')
    {
        val = true
    }
   
    if(subtask.getCustomFieldValue(customField).toString() == 'Unspecified')
    {
        unspecified = true
    }
   
}

if(val)
{
    def fieldConfig = customField.getRelevantConfig(underlyingIssue)
    def param = ComponentAccessor.optionsManager.getOptions(fieldConfig)?.find { it.toString() == 'Yes' }
    getFieldByName(cfName).setFormValue(param)

}
else
{
    if(unspecified)
    {
        def fieldConfig = customField.getRelevantConfig(underlyingIssue)
      def param = ComponentAccessor.optionsManager.getOptions(fieldConfig)?.find { it.toString() == 'Unspecified' }
        getFieldByName(cfName).setFormValue(param)

    }
    else
    {
        def fieldConfig = customField.getRelevantConfig(underlyingIssue)
      def param = ComponentAccessor.optionsManager.getOptions(fieldConfig)?.find { it.toString() == 'No' }
        getFieldByName(cfName).setFormValue(param)
    }  
}

 

1 answer

1 accepted

1 vote
Answer accepted

Hi Jorden,

I might be able to help you here. Please advise when exactly do you want this to trigger? 

Deleted user Sep 28, 2018

I wanted to have this calculated when a users was viewing the issue, so the value would always be up to date.

Also currently I found that this part of the code:

def fieldConfig = customField.getRelevantConfig(underlyingIssue)
      def param = ComponentAccessor.optionsManager.getOptions(fieldConfig)?.find { it.toString() == 'OPTION NAME' }
        getFieldByName(cfName).setFormValue(param)

throws a stack overflow in the error log of jira.

 

But today I think I read that it would be better to create the functionality with Scripted Fields? 

If I were to use scripted fields, would it then be saved in the issue as well? (so it shows up when you do a JQL search for it) And how would I go about that?

 

Thanks!

Kind regards

Jorden

Indeed, scripted field seems to be the best solution here. As far as JQL search is concerned it should be fine as long as you pick the correct searcher in your field config.

As for the code, it is as follows:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue

CustomFieldManager cfMgr = ComponentAccessor.getCustomFieldManager()
CustomField cf = cfMgr.getCustomFieldObjectByName("Performance Reporting impact")
Collection<Issue> subtasks = issue.getSubTaskObjects()
String result = "No"
if(subtasks){
if(subtasks.any{it.getCustomFieldValue(cf).getValue().equals("Yes")}){
result = "Yes"
}else if(subtasks.any{it.getCustomFieldValue(cf).getValue().equals("Unspecified")}){
result = "Unspecified"
}
}
return result
Deleted user Sep 30, 2018

Hi Ivan

Thank you for your response. In your code I see the result is given as a string value. Is it also possible to have this applied to a select list?

The custom field that I'm working with is on both parent and sub-tasks and should be a simple "Yes" or "No" select to prevent people from typing mistakes in the sub-tasks if I were to use text fields. Your current solution would work if I either made the field a text field or if I had a text field for the parent issue and a select list for the sub-task issues.

Is there a way to make it work with select lists as well? Or am I completely of track and should this work for this case as well?

Thanks!
Kind regards
Jorden

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Marketplace Apps & Integrations

Staying organized with Jira: best practices for a better project management

Project managers know this problem: A “mountain of work” lays in front of you, and you don’t know how and where to tackle them. Different to-dos lie ahead, but just one task after the other can be ha...

174 views 2 1
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you