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());
Related to broader question here: https://answers.atlassian.com/questions/44206040
Community moderators have prevented the ability to post new answers.
Main issue for cusotm fields is to know type of returned value.
Whant type is for custom field you get information from?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This type of field returns List<Option> since you need a loop to get all values. Here is code example to get all selected options as single string:
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.customfields.option.Option import com.atlassian.jira.issue.fields.CustomField CustomField customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("fieldName") StringBuilder stringBuilder = new StringBuilder() ((List<Option>) issue.getCustomFieldValue(customField)).each { stringBuilder.append(it.getValue()).append(", ") } return stringBuilder.toString()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.