I am attempting to set a radio button based on the value of other radio buttons. I'm trying to do this in a post-function for the Create transition and two other transitions that are later in the workflow.
It works fine in the the later transitions, but does not set the radio button in the Create transition and does not throw any error that I see.
We are using JIRA Data Center 7.13 and Adapativist ScriptRunner 5.5.3
Here is a simplified version of my code.
// Script to set Radio Button field based on other Radio Button.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def changeHolder = new DefaultIssueChangeHolder()
// Get value of source radio button field. Values are "True" and "False"
def estimated_cf = customFieldManager.getCustomFieldObjects(issue).find {it.name == "Estimated Total Spend Exceeds 250k"}
String estimated_cf_val= issue.getCustomFieldValue(estimated_cf)
// Get value of destination radio button field. Initial value is NULL
def capitalizable_cf = customFieldManager.getCustomFieldObjects(issue).find {it.name == "Capitalizable"}
// Get the Option values for the different radio button options of the destination field
def cfConfig = capitalizable_cf.getRelevantConfig(issue)
def optionTrue = ComponentAccessor.optionsManager.getOptions(cfConfig)?.find { it.toString() == "True" }
def optionFalse = ComponentAccessor.optionsManager.getOptions(cfConfig)?.find { it.toString() == "False" }
if ( estimated_cf_val.equalsIgnoreCase("True") ) {
capitalizable_cf.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(capitalizable_cf), optionTrue), changeHolder)
}
else {
capitalizable_cf.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(capitalizable_cf), optionFalse), changeHolder)
}
Hi,
If this works in other transitions, it might be because the script postfunction is executed prior the "Re-index an issue to keep indexes in sync with the database.", and you might want to re-arrange them ?
Antoine
Thank you, Antione. Your suggestion helped me.
I realized I was using code to update data in the database, but the Create Issue post function had not run yet so there was nothing in the database to update. I needed to put the script after the Create Issue post function.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.