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)
}
}