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

Set radio button custom field is not working

Mobileye Atlassian Licenses January 15, 2018

Hi,

I'm trying to update a radio button custom field with one of the values in this field using post-function in a specific transition.

I wrote the following groovy script:

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import static groovy.io.FileType.FILES


import org.apache.log4j.Logger
import org.apache.log4j.Category

def Category log = Category.getInstance("com.onresolve.jira.groovy.Condition")
log.setLevel(org.apache.log4j.Level.DEBUG)

def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()


def cField = customFieldManager.getCustomFieldObject('customfield_13899') //Confirm Bundle use - custom field
def cFieldValue = issue.getCustomFieldValue(cField) as String
def cField2 = customFieldManager.getCustomFieldObject('customfield_13893') //Bundle changes - custom field
def cFieldValue2 = issue.getCustomFieldValue(cField2) as String


log.info("The Bundle change current value is: "+ cFieldValue2)

if (cFieldValue=="Using Bundle as is") {
def changeHolder = new DefaultIssueChangeHolder()
cField2.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(cField2), "Bundle with no changes"),changeHolder)
//log.info("Need to write using Bundle as is")
} else if (cFieldValue=="Pulling additional algorithmic trees into an existing Bundle") {
def changeHolder = new DefaultIssueChangeHolder()
cField2.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(cField2), "Bundle change requested"),changeHolder)
//log.info("Need to write bundle change requested")
}

 

My goal is to update the radio button custom field - cField2 with a specific value depending on the value in the custom field - cFieldValue.

Do you know why the radio button custom field is not updating?

 

 

Thanks,

Bar

1 answer

Suggest an answer

Log in or Sign up to answer
0 votes
Trudy Claspill April 26, 2019

I believe that you cannot set the radio button field to a text value as you are trying to do in this line

cField2.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(cField2), "Bundle with no changes"),changeHolder)

You have to find the option that equates to the string, and then use that in setting the field. So something link this.

def cfConfig = cField2.getRelevantConfig(issue)
def option1 = ComponentAccessor.optionsManager.getOptions(cfConfig)?.find { it.toString() == 'Bundle with no changes' }
def option2 = ComponentAccessor.optionsManager.getOptions(cfConfig)?.find { it.toString() == 'Bundle change requested' }

 

Then change your updateValue statements to use option1 and option2.

if (cFieldValue=="Using Bundle as is") {
def changeHolder = new DefaultIssueChangeHolder()
cField2.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(cField2), option1),changeHolder)
//log.info("Need to write using Bundle as is")
}
else if (cFieldValue=="Pulling additional algorithmic trees into an existing Bundle") {
def changeHolder = new DefaultIssueChangeHolder()
cField2.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(cField2), option2),changeHolder)
//log.info("Need to write bundle change requested")
}
TAGS
AUG Leaders

Atlassian Community Events