Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Groovy change option's parent

Hi!

Is there any possibility to change parent option or parentOptionId of allready existing com.atlassian.jira.issue.customfields.option.Option?

When creating it's possible to set by 

optionsManager.createOption(FieldConfig fieldConfig, Long parentOptionId, Long sequence, String value)

but if option allready exists?

1 answer

0 votes
Gustavo Félix
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.
September 24, 2020

Hi @Колыбаев Игорь Михайлович 

If I understood you correctly, you want to change an option inside a select Field ?
If this is correct, this works for me inside a workflow transition:

import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.atlassian.jira.issue.CustomFieldManager
i
mport com.atlassian.jira.issue.context.IssueContextImpl
def selectCustomField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("yourSelectField")
def selectField = issue.getCustomFieldValue(selectCustomField)
IssueContextImpl issueContext = new IssueContextImpl(issue.getProjectObject(), issue.getIssueType())
def selectConfig = selectCustomField.getRelevantConfig(issueContext)
def selectOptions = ComponentAccessor.optionsManager.getOptions(selectConfig)
for(select in selectOptions){
          if(select.toString().contains("option1")){
            selectOptions.setValue(select,"newOption1")
          }
}

This is another example on a behaviour.
https://library.adaptavist.com/entity/set-behaviour-multi-and-single-select-options-and-value

Options have a parameter Long parentOptionId, used in cascading select fields, which can be setted during creation of an Option. My question is how parent Option can be modified for an allready existing Option. I meen changing parent Option to some another.

Suggest an answer

Log in or Sign up to answer