Conditional Fields based on other Field Values?

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é

3 answers

2 votes

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

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.

 

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

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,981 views 12 18
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot