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é

4 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.

Hi,

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

Thanks

Camille

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 Sign up to answer
Community showcase
Published Nov 27, 2018 in Portfolio for Jira

Introducing a new planning experience in Portfolio for Jira (Server/DC)

In the past, Portfolio for Jira required a high degree of detail–foresight that was unrealistic for many businesses to   have–in   order to produce a reliable long-term roadmap. We're tur...

2,522 views 15 21
Read article

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