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 Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,934 views 12 18
Join discussion

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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot