Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

ScriptRunner: How to create a canned PostFunction with dependent input dropdowns?

Peter_Velosy
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 1, 2019

I would like to have a canned PostFunction which has two input parameters, both selectable from dropdown fields (this part is already implemented). Now I would like the two dropdowns to depend on each other, i.e. whenever the first dropdown's value changes, the second dropdown reloads with a filtered result set.

I thought the "params" parameter below does the trick, but it seems that the getParameters() method is only called once (I thought it would be called every time an input component changes its value on the UI so that it would be possible to build dependent input components). Do we have any way to achieve this? Thank you!

@Override
List getParameters(Map params) {

 

1 answer

0 votes
PD Sheehan
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.
August 1, 2019

While I had no idea how to answer you... I was sure it had to be possible and was curious.

So I found that one of the built-in script rmo the admin menu has a dynamic field.

Then, I had a look at the getParameters method it uses (you can look into the .jar file for scriptrunner to get such examples).

And it looks like this:

List getParameters(Map params) {

// we do need the transformations here because we need the right user keys immediately in order to get the user's dashboards and filters
def fromUserId = params[FIELD_FROM_USER_ID] ? getUserKeyFromName(FIELD_FROM_USER_ID, params[FIELD_FROM_USER_ID] as String) : null
def toUserId = params[FIELD_TO_USER_ID] ? getUserKeyFromName(FIELD_TO_USER_ID, params[FIELD_TO_USER_ID] as String) : null

def rt = [
UserParamProvider.getSingleUserKeyParam(FIELD_FROM_USER_ID, 'From user', "User to transfer items from", fromUserId),
UserParamProvider.getSingleUserKeyParam(FIELD_TO_USER_ID, 'To user', "User to transfer items to", toUserId),
[
name : FIELD_DASHBOARD_IDS,
label : 'Dashboards',
type : "multilist",
value : params[FIELD_DASHBOARD_IDS] ?: [],
values : fromUserId ? getDashboardsForUser(fromUserId) : [:],
description: "Dashboards to change ownership",
],
[
name : FIELD_FILTER_IDS,
label : 'Filters',
type : "multilist",
values : fromUserId ? getSearchRequestsForUser(fromUserId) : [:],
value : params[FIELD_FILTER_IDS] ?: [],
description: "Filters to change ownership",
],
]

rt
}

Note this line:

values : fromUserId ? getSearchRequestsForUser(fromUserId) : [:],

Looks like this will be blank when the first field (fromUserId) is blank ... when that field is not empty, it calls the function to return the values. 

You should be able to extrapolate from that for your use case.

Suggest an answer

Log in or Sign up to answer