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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Tuesday in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

256 views 1 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