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

Get custom field single select dropdown value on create

Kamal Iqlaas Ismail September 1, 2021

Hi everyone, hope this question finds you in good wealth.

As per the subject above, would like to know how it is executed, as most tutorials I found, have done it after the issue is created.

And in the official documentation for getValue , getValue() only Gets the value that is current in the form.

I would like to know how to get the values of the single select dropdown custom field of an issue before the issue gets created.

Trying to achieve this in the Behaviour console area.

For example, this is the custom field with single select dropdown

FormField ffOptionsField = getFieldById("Dropdown Custom Field")

In the Inspect Element, this is the structure:

<div id="qf-field-customfield_111" class="qf-field qf-field-active" style="display: block;">
<div class="field-group">
<label for="customfield_111">Dropdown Custom Field</label>
<select class="select cf-select clientreadonly" name="customfield_111" id="customfield_111" disabled="">
<option value="-1">None</option>
<option value="000">Option One</option>
<option value="111">Option Two</option>
<option value="222">Option Three</option>
</select>
</div>
</div>

Am trying to get the 'Option One' to check against another list that I have managed to get from a json file. so the function would look like this:

def getInFieldOptions(String valueFromJson){
def fieldOptionsList = ffOptionsField.getValue() // this would get null
if (valueFromJson in fieldOptionsList) {
ffOptionsField.setFormValue(valueFromJson)
} else {
ffOptionsField.setFormValue("-1")
}
}

But, the code ffOptionsField.getValue() return null for me.

Any pointers would be helpful!

 

2 answers

1 accepted

Suggest an answer

Log in or Sign up to answer
0 votes
Answer accepted
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 1, 2021

You can get the full list of options application from a custom field by calling the Jira Java api.

For example:

import com.atlassian.jira.component.ComponentAccessor
def cfMgr = ComponentAccessor.customFieldManager
def optMgr = ComponentAccessor.optionsManager

def formField = getFieldByName('Drop Down Field')

def customField = cfMgr.getCustomFieldObject(formField.fieldId)
def config = customField.getRelevantConfig(issueContext)
def options = optMgr.getOptions(config)

//find the option that match your valueFromJson
def option = options.find{it.value == valueFromJson}

//now set the form field to that option
if(option){
formField.setFormValue(option.optionId)
}else {
formField.setFormValue('-1')
}
Kamal Iqlaas Ismail September 1, 2021

With minor adjustments,

we got what we intended to do.

Appreciate the code bit of customFieldManager and optionsManager.

Thank you @Peter-Dave Sheehan for your prompt response.

BR,

Kamal

0 votes
Leo
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 1, 2021

Hi @Kamal Iqlaas Ismail,

 

Couple of questions

1. you want to get filled value of that field or all possible options available for that field?

2. Is this initializer script or server side script of select list field?

 

Regards,

Leo

Kamal Iqlaas Ismail September 1, 2021

Hi @Leo , appreciate your response.

1. On Create screen, the dropdown field is blank, so I am looking to get the dropdown field filled with the value from all options of that dropdown that matches with the value from the json.

2. It's a server side script of the select list field.

Hope this get us to the right direction.

Regards,

Kamal 

Leo
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 1, 2021

That's good to know. and the exact script is provided by @Peter-Dave Sheehan below would meet your requirement
but only thing is it'll be executed only if the select list field gets changed as per your current configuration

if you have a json value predefined and not fetching from current screen/form then initializer would be the best choice to go with

of if you are getting json value from another field then the same script as server side script of the source field

 

BR,

Leo

Kamal Iqlaas Ismail September 1, 2021

Appreciate it Leo,

Yes we are looking at @Peter-Dave Sheehan solution.

KR,

Kamal

TAGS
AUG Leaders

Atlassian Community Events