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!
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
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.