Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,361,625
Community Members
 
Community Events
168
Community Groups

Changing custom field value (radio button) according to other custom field value.

Hi,

 

I have 2 custom fields:

1. scripted field that calculates some integer value.

2. Radio button with 5 options.

 

I want to add a behavior to the scripted field that will cause to a changing of the Radio button field. The condition should be this:

If (scripted field value <= 0 ){

Radio button option = A

}

else{

Keep the original value of the Radio button field.

}

 

 

Can anyone please assist me with this?

 

Thanks in Advance!

1 answer

0 votes

Hi,

Are you starting from scratch when it comes to scripting in Jira and Behaviours or do you need minor tweaks? 

For setting radio buttons I'd recommend checking this answer here: https://community.atlassian.com/t5/Jira-questions/Error-in-Groovy-script-while-updating-radio-button-custom-Field/qaq-p/314350

If you need more advanced help feel free to reach out.

Hi, actually I'm starting from scratch.

 

I found this code and tried to implement it :

 

import com.atlassian.jira.component.ComponentAccessor

// set a select list value -- also same for radio buttons
def faveFruitFld = getFieldByName("RadioButtonName")
def optionsManager = ComponentAccessor.getOptionsManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def customField = customFieldManager.getCustomFieldObject(faveFruitFld .getFieldId())
def config = customField.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(config)


def daysObj = getFieldByName("ScriptedFieldName")
def days = daysObj.getValue() as Integer

if(days <= 0){
def optionToSelect = options.find { it.value == "A" }
faveFruitFld.setFormValue(optionToSelect.optionId)
}
else{
*****
}

 

*****What should be the code under else to keep the original value of the radio button? 

Hi I got a notification for an answer, but it seems to have disappeared.

Your else clause should be empty if your not intending to change anything in the custom field.

Hi , 

 

Indeed my comment is disappeared.

 

Actually I'm starting from scratch .

I've found this code and tried to implement it:

 

import com.atlassian.jira.component.ComponentAccessor

// set a select list value -- also same for radio buttons
def faveFruitFld = getFieldByName("RadioButtinNameField")
def optionsManager = ComponentAccessor.getOptionsManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def customField = customFieldManager.getCustomFieldObject(faveFruitFld.getFieldId())
def config = customField.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(config)


def daysObj = getFieldByName("scriptedFieldName")
def days = daysObj.getValue() as Integer

if(days <= 0){
    def optionToSelect = options.find { it.value == "Beyond Limit for Installation" }
 faveFruitFld.setFormValue(optionToSelect.optionId)
}
else{
******
}

****** what should be the code under the else section if I want to keep the original value that was set form the radio button?

Hi,

I responded with: "Your else clause should be empty if your not intending to change anything in the custom field."

Does it work otherwise? As in, does your if-clause work as expected?

Hi again,

 

Thanks for your reply.

 

Actually, I think that the if-clause doesn't work as now while opening the edit screen, for all issues the value in the "Installation Status" field, set to "Beyond Limit for Installation" (no matter what is the value of the scripted field ).

As I mentioned, I am not familiar with Jira behaviors so much, and I have some general questions:  

1. should I write the script as Initialiser Function or as a specific script on one of the fields in  the behavior?

2. Does it possible to set the value of the radio button not only by editing the issue?

Meaning, currently as I mentioned.  while opening the edit screen, for all issues the value in the "Installation Status" field, set to "Beyond Limit for Installation". But what I really want is an automatic update of the field without editing the issue.

1. I would write it as an Initialiser function since you want the behaviour when you open the issue, but test it both ways and see which you prefer.

2. You mean setting a default value? You can do that in the custom field settings or in the workflow.

Feel free to reach out on LinkedIn if you want further help with this one.

When you say automatic update, do you mean that whenever the value of "scriptedFieldName" changes, the "Installation status" field will be set to some value?

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira

Online AMA this week: Your project management questions answered by Jira Design Lead James Rotanson

We know that great teams require amazing project management chops. It's no surprise that great teams who use Jira have strong project managers, effective workflows, and secrets that bring planning ...

208 views 1 6
Read article

Atlassian Community Events