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

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

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
Asked in Jira Service Desk

Calling all Insight users, we need your help!

Hello Insight users,  As part of our (Mindville's) acquisition by Atlassian, our training team is looking to build some new Insight training materials. It would really helpful if you can ...

54 views 0 0
View question

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you