Forums

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

Post function to set radio button doesn't work in Create transition

Trudy Claspill
Contributor
April 29, 2019

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)

}

 

1 answer

1 accepted

0 votes
Answer accepted
Antoine Berry
Community Champion
April 30, 2019

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

Trudy Claspill
Contributor
April 30, 2019

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.

Like Antoine Berry likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events