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,294,696
Community Members
 
Community Events
165
Community Groups

Get custom field single select dropdown value on create

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

0 votes
Answer accepted

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')
}

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 Sep 01, 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

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 Sep 01, 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

Appreciate it Leo,

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

KR,

Kamal

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Posted in Jira Service Management

Jira Service Management Documentation Opportunities

Hello everyone, Hope everyone is safe! A few months ago we posted an article sharing all the new articles and documentation that we, the AMER Jira Service Management team created. As mentioned ...

274 views 0 6
Join discussion

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