Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.
×Hello everyone
I've searched far and wide but couldn't find a solution appropriate for my issue.
In one of my listeners, I'm able to get the string value of my custom dropdown box like so.
def ComponentAccessor = com.atlassian.jira.component.ComponentAccessor
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def KasseCF = customFieldManager.getCustomFieldObjectByName("Kasse")
def issueKasse = issue.getCustomFieldValue(KasseCF)
This will return the exact displayed value and not the ID.
How can I get the same result in my behaviour?
I've tried using .getValue() and also almost the same setup above but instead used underlyingIssue?.getCustomFieldValue(KasseCF) since "issue" seems to be unavailable in behaviours but both options returned the ID of the selected option...
Can someone help me out here?
Thanks!
Hi Marius,
I am not sure if you are trying to get the value of a custom field which is on the dialog or a custom field that is on the issue underneath. Either way here I have provided different ways of dealing with options and getting custom field values etc.
try playing with some of this:
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
// different ways of getting field values
def yourField = getFieldById(getFieldChanged())
def yourFieldAnotherWay = getFieldByName("Your Field")
def yourFieldValue = yourField.getValue()
// get the options avaliable for that custom field
def customField = customFieldManager.getCustomFieldObject(yourField.getFieldId())
def config = customField.getRelevantConfig(getIssueContext())
def getOptionById = ComponentAccessor.getOptionsManager().getOptions(config).find {it.optionId == yourFieldValue}
// get all the options and find the one for the id returned
def getOptionById = ComponentAccessor.getOptionsManager().getAllOptions().find{it.optionId == yourFieldValue}
Thannks
Johnson Howard (Adaptavist)
Hey Johnson
Thanks for your reply!
I am trying to get the string value of my customfield dropdown box which is on the create issue screen.
Depending on their selection, I would like to set the values of other fields.
All your suggestions only provide me with the ID of the selected option and not the text value of it.
Extract of my debug log:
[c.o.j.groovy.user.FieldBehaviours] Form field ID: customfield_11008, value: 10707
My script:
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
import org.apache.log4j.Level
log.setLevel(Level.DEBUG)
/*log.debug("--------------------This is to test Behaviours Logging----------------")*/
def fieldChanged = getFieldById(getFieldChanged())
def getOptionById = ComponentAccessor.getOptionsManager().getAllOptions().find{it.optionId == fieldChanged.getValue()}
log.debug(fieldChanged)
if(fieldChanged == "customfield_11008")
{
log.debug(getOptionById)
}
Regards,
Marius
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Marius,
Have you tried doing this on the option that is returned:
getOptionById.value
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This also returns the ID unfortunately :/
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
fieldChanged.value.toString()
try that
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That was it! :)
Thanks a lot!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Here Select_List_custom is dropDown field
def optionsManager = ComponentAccessor.getComponent(OptionsManager)
def customField = customFieldManager.getCustomFieldObject(getFieldChanged())
def config = customField.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(config)
Select_List_custom.setFieldOptions(options.findAll {it.value as String in ['India','USA','abc','pqr','xyx',.........]})
Try this pass value of whatever you have in dropdown in options.findAll { }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi John
I have same requirement where based on selected value in Select list I need to make few fields hidden and others visible and also required.
def cfField = getFieldByName("Software Name")
def CatVal = getFieldById(getFieldChanged())
System.out.println("Cat Match::: " + CatVal)
def selectedOption = CatVal.getValue() as String
def isOtherSelected = selectedOption == "JIRA Account"
cfField.setHidden(true)
System.out.println("Cat Val::: " + selectedOption)
if(!isOtherSelected){
cfField.setHidden(false)
cfField.setRequired(true)
}
Issue if I am not able to get value at all - as my server logs only print first statement System.out.println("Cat Match::: " + CatVal) and not moving further. I used all possible options to get value but no luck. Can you please help here. I also used one mentioned above in discussion.
here is the server log: you can see it just prints changed values of field but not moving further in script:
Cat Match::: Form field ID: customfield_10401, value: 10721
Cat Match::: Form field ID: customfield_10401, value: 10731
Cat Match::: Form field ID: customfield_10401, value: 10997
Cat Match::: Form field ID: customfield_10401, value: 10711
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey Jyoti
I suggest you post this as a new question. Johnson won't see this as he's not getting notifications from this, only me, the original poster.
Hijacking old and solved posts is bad practise anyway.
Best Regards
Marius
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.