Conditional Fields based on other Field Values?

Andre Saade May 5, 2016

Hello,

I'm currently creating a prototype to evaluate JIRA and ScriptRunner, and have some issues I need to learn about.
1- How do I set a "User Picker" field to display values based on another field's value on the same screen when creating an issue.
i.e: I have multiple Centers in my organization. If user picks Center = HQ, I need the "Manager" field to display only HQ Managers.
2- Also , what is the best way to set a series of users in the background based on that same choice. The issues will get assigned to those users as the flow moves forward. Currently I set a post function with the attached script. I then copy those values into "User" fields during transitions.

Thank you,
André

4 answers

3 votes
Camille Lecerf April 13, 2018

Hi,

Are there any updates availables about this please ?
I am interested in this feature in Scriptrunner.

Thanks

Camille

2 votes
adammarkham
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.
May 5, 2016

We have been investigating this since you posted this question. The short answer is its just about possible with Behaviours but we don't really provide an easy way of doing this sort of thing unless you write your own REST endpoint.

I have raised a feature request and we will add this feature in a future sprint. You can track the progress of it here: https://productsupport.adaptavist.com/browse/SRJIRA-1900

If your going to roll your own thing then I suggest you read up on the documentation I have linked you to here.

We do a similar thing for picking issues, you can see the examples here: https://scriptrunner.adaptavist.com/latest/jira/behaviours-conversions.html

If your comfortable with the examples provided above then you could write your own.

Using behaviours and setting the following script on the field where the user selects "managers" would work if you have defined those endpoints yourself like in the examples:

if (getActionName() == "Create") {

    def selectListField = getFieldById(fieldChanged)
    def multiUserPicker = getFieldByName("TextFieldForUsers")

    if (selectListField.value == "Managers") {
        // set manager users here using multiUserPicker
        multiUserPicker.convertToMultiSelect([
                ajaxOptions: [
                        url : getBaseUrl() + "/rest/scriptrunner/latest/custom/myissuepicker/managers",
                        query: true,
                        formatResponse: "general"
                ]
        ])
    } else if (selectListField.value == "Other") {
        // set other users
        multiUserPicker.convertToMultiSelect([
                ajaxOptions: [
                        url : getBaseUrl() + "/rest/scriptrunner/latest/custom/myissuepicker/otherusers",
                        query: true,
                        formatResponse: "general"
                ]
        ])
    }
}

For the second question, it sounds like if you want to select a series of users based on a transition change then post-function are the best way.

 

Hope this helps.

0 votes
Andre Saade May 5, 2016

I was planning on using it for single user picker, but would be helpful to know if it were also feasible for multi user picker

0 votes
adammarkham
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.
May 5, 2016

For 1) is it a single user picker or a multi one you are using?

Also would you be able to add the following tag to your answer so other people can find it when they search: groovy-script-runner

Thanks.

 

Suggest an answer

Log in or Sign up to answer