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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

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,555,326
Community Members
 
Community Events
184
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
Sana Safai
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Jun 28, 2018

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? 

Sana Safai
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Jun 28, 2018

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?

Sana Safai
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Jun 28, 2018

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.

Sana Safai
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Jul 10, 2018

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.

Sana Safai
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Jul 11, 2018

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
AUG Leaders

Atlassian Community Events