change drop down value of custom field based on status

Raju KC
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 24, 2013

I want to change drop down value of custom field based on status.
For eg:
If status is StatusA, then value in drop down should be A1,A2.
If status is StatusB, then value in drop down should be A1,B1,B2.
How can i achieve this?

5 answers

1 accepted

0 votes
Answer accepted
Florin Manaila
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 25, 2013

You can use the JJupin plugin for that with its Live Fields fieature. Here's a similar example to what you're looking for:

http://confluence.kepler-rominfo.com/display/TR/Restricting+resolutions+based+on+issue+type

Kaushik Roy September 4, 2015

Its Not working for me. Do we have any sample code for help?

0 votes
saranya22 April 9, 2019

You can achieve this using Behaviours with the below code. Behaviours is part of Adaptivist ScriptRunner plugin.
Select the drop down field and add the below server side script:

import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.getCustomFieldManager()

def optionsManager = ComponentAccessor.getOptionsManager()

def formField = getFieldById(getFieldChanged())

def customField = customFieldManager.getCustomFieldObject(formField.getFieldId())

def config = customField.getRelevantConfig(getIssueContext())

def options = optionsManager.getOptions(config)

if (underlyingIssue.getStatus().getName() == "A") {

 

def optionsMap = options.findAll {

it.value in ["A1", "B2"]

}.collectEntries {

[

(it.optionId.toString()) : it.value

]

}

formField.setFieldOptions(optionsMap)

} 

if (underlyingIssue.getStatus().getName() == "B") {

 

def optionsMap = options.findAll {

it.value in ["A1", "B1", "B2"]

}.collectEntries {

[

(it.optionId.toString()) : it.value

]

}

formField.setFieldOptions(optionsMap)

}
0 votes
saranya22 April 9, 2019

You can use the below code in Behaviours which is part of Adaptivist ScriptRunner plugin:

Select the dropdown field and then add below serverside script:

 

import com.atlassian.jira.component.ComponentAccessor 

def customFieldManager = ComponentAccessor.getCustomFieldManager()

def optionsManager = ComponentAccessor.getOptionsManager()


def formField = getFieldById(getFieldChanged())

def customField = customFieldManager.getCustomFieldObject(formField.getFieldId())

def config = customField.getRelevantConfig(getIssueContext())

def options = optionsManager.getOptions(config)


if (underlyingIssue.getStatus().getName() == "A") {


def optionsMap = options.findAll {

it.value in ["A1", "A2"]

}.collectEntries {

[

(it.optionId.toString()) : it.value

]

}

formField.setFieldOptions(optionsMap)

}

if (underlyingIssue.getStatus().getName() == "B") {

def optionsMap = options.findAll {

it.value in ["A1", "B1", "B2"]

}.collectEntries {

[

(it.optionId.toString()) : it.value

]

}

formField.setFieldOptions(optionsMap)

}
0 votes
Mario Prada Arroyo April 25, 2013

hi!!

you can use Database Custom Field (https://marketplace.atlassian.com/plugins/com.keplerrominfo.jira.plugins.databasecf) and a auxiliar database table with the relationship between status and drop down field.

The database table will have the following values:

Status A - A1

Status A - A2

Status B - A1

Status B - B1

Status B - B2

So, the query will be dependant on status field :-)

Hope this helps.

0 votes
Mizan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 24, 2013

You can use Behaviours plugin for this , You will need to write a custom groovy script which will check for the status and display options in the required customfield .

refer the below docs for examples

https://jamieechlin.atlassian.net/wiki/display/JBHV/JIRA+Behaviours+Plugin

https://jamieechlin.atlassian.net/wiki/display/JBHV/Miscellaneous+Behaviours+Examples#MiscellaneousBehavioursExamples-Addorremoveoptionstosingleormulti-selectfields

Raju KC
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 25, 2013

is it possible via javascript?

Raju KC
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 25, 2013

Will script runner plugin be used instead of Behaviours plugin?

Mizan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 25, 2013

It wont be possible via javascript since the status is not present on the screen/pop up

Mizan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 25, 2013

Script runner cannot cannot be used to change the values of a dropdown on the screen , script runner can provide a post function which will set the value to the customfield based on status

Using behaviours plugin for this type of customization is better than pasting javascript in the fields description

Suggest an answer

Log in or Sign up to answer