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
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Thursday in Jira

5 ways you can make the most of Jira Software and Bitbucket Cloud

As part of the Bitbucket product team I'm always interested in better understanding what kind of impact the use of our tools have on the way you work. In a recent study we conducted of software devel...

76 views 0 5
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