Update a checkbox on a parent issue based on subtask value

Hi,

I was wondering if anyone can help, using script runner I need to update a checkbox on a parent issue based on a value in a subtask. The script will be executed when the subtask is transitioned into a closed state.

I'm trying to write a custom script.

1 answer

I've written the following so far -

import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.customfields.manager.OptionsManager;
import com.atlassian.jira.issue.fields.config.FieldConfig;
import com.atlassian.jira.issue.ModifiedValue;
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder;



MutableIssue parent = issue.getParentObject();
ComponentManager componentManager = ComponentManager.getInstance();
def customFieldManager = componentManager.getCustomFieldManager();
def optionsManager = ComponentManager.getComponentInstanceOfType(OptionsManager.class)

def cf = customFieldManager.getCustomFieldObjects(parent).find {it.name == "New Environment"}
def fieldConfig = cf.getRelevantConfig(parent);
def uat_value = ComponentAccessor.optionsManager.getOptions(fieldConfig)?.find { it.toString() == 'UAT' }

def changeHolder = new DefaultIssueChangeHolder();
def modVal = new ModifiedValue(parent.getCustomFieldValue(cf),uat_value.toString());

cf.updateValue(null,parent,modVal,changeHolder);

----------------------------------------

I get the following error -


java.lang.ClassCastException: com.atlassian.jira.issue.customfields.option.LazyLoadedOption cannot be cast to java.util.Collection

        at com.atlassian.jira.issue.customfields.impl.AbstractMultiCFType.createValue(AbstractMultiCFType.java:41)

        at com.atlassian.jira.issue.fields.CustomFieldImpl.createValue(CustomFieldImpl.java:854)

        at com.atlassian.jira.issue.fields.CustomFieldImpl.updateValue(CustomFieldImpl.java:522)

        at com.atlassian.jira.issue.fields.CustomFieldImpl.updateValue(CustomFieldImpl.java:504)

        at com.atlassian.jira.issue.fields.OrderableField$updateValue.call(Unknown Source)

        at Script102.run(Script102.groovy:22)



Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 27, 2018 in Portfolio for Jira

Introducing a new planning experience in Portfolio for Jira (Server/DC)

In the past, Portfolio for Jira required a high degree of detail–foresight that was unrealistic for many businesses to   have–in   order to produce a reliable long-term roadmap. We're tur...

2,943 views 19 22
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you