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