Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Transfer checkbox values in subtask to parent ticket label field?

James Fishwick November 15, 2016

Sort of an odd use case, but here is what I am trying to do:

There are several checkbox fields in a subtask. When these fields are edited (a checkbox state changes) the human readable values of each checkbox option needs to snake_cased and added to the parent ticket as a label. Ideas?

Alternatively I could use the JIRA generated checkbox ids and have a map in the post function to correlate things to strings.

---

Here is some starter code where I try to get the checked values in a custom field and apply them to a text field (on the same ticket). But no joy yet. Some superfluous junk in here, I know.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.project.Project
import groovy.transform.Field
import com.atlassian.jira.issue.customfields.option.LazyLoadedOption
import com.atlassian.jira.config.SubTaskManager
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.customfields.option.*
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
    
def cfManager = ComponentAccessor.getCustomFieldManager()
def componentManager = ComponentManager.instance
def optionsManager = ComponentManager.getComponentInstanceOfType(OptionsManager.class)
def customFieldManager = ComponentAccessor.getCustomFieldManager()
 
//Get parent issue
Issue issue = (Issue) event.issue;
//Check, that it is a subtask type issue
if(!issue.isSubTask())
    return
 
MutableIssue parentIssue = issue.getParentObject();
Set issueLabels = parentIssue.getLabels();
def customField = customFieldManager.getCustomFieldObject("customfield_27132")
def selectedValues = customField.getValue(issue)*.value
def target = customFieldManager.getCustomFieldObject("customfield_27736")
String labels = selectedValues.join(',')
//CustomField cf = cfManager.getCustomFieldObject(condField)
//Options options = cf.getOptions(null, cf.getRelevantConfig(issue), null);

//def cfTarget = cfManager.getCustomFieldObject(target)
//issue.setCustomFieldValue(target, selectedValues.join(",")) 
//issue.setCustomFieldValue(target, "test")
target.updateValue(null, issue, new ModifiedValue(target, labels), new DefaultIssueChangeHolder());

 

 

2 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
James Fishwick December 1, 2016

@Jamie Echlin (Adaptavist) can you look at my code above? See comment below.

0 votes
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 17, 2016

I'm not sure which bits you are having problems with... none of the constituent parts of this task are hard, but I'm not sure anyone is going to write it for you.

But some things to think about - you seem to be saying you don't care about the toggle state of the checkbox, just that it's different from the saved value?

You don't want to have multiple values for the same checkbox in the case of someone toggling it multiple times, so "on change", I would get the value from the issue, compare with the current value. For those items changed you can use eg http://groovyconsole.appspot.com/script/337001 to create the label string, then label the parent issue.

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 17, 2016

Actually sounds like something you should do in an "Issue Updated" listener.

James Fishwick November 17, 2016

Perfect, just looking for a little guidance like this. 

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 17, 2016

OK, come back to us for specifics if you need it.

James Fishwick November 29, 2016

I'm working towards the final solution by just trying to get the checked values for a filed and transfer them to a text field. But having trouble. Can you look at my code added to the question?

TAGS
AUG Leaders

Atlassian Community Events