Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

ScriptRunner Behaviour Initializer list of components

Jon Kocen
Contributor
July 8, 2020

I am using the ScriptRunner Behaviour Initialzer on a text filed and want to populate it with a list of components that users can pick from. I am using this as a look up since I don't have access to any server side tools to create the data set.

I am using this script but the Team field doesn't get populated. The API call is valid and returns data from my browser.

getFieldByName("Team").convertToMultiSelect([
ajaxOptions: [
url : getBaseUrl() + "/rest/api/latest/project/GA/components",
query: true, // keep going back to the sever for each keystroke

// this information is passed to the server with each keystroke
data: [
currentJql : "project = GA ORDER BY component ASC",
label : "Select the Team"

// specify maximum number of issues to display, defaults to 10
// max : 5,
],
formatResponse: "general"
],
css: "max-width: 500px; width: 500px",
])

1 answer

1 accepted

1 vote
Answer accepted
Italo Qualisoni [e-Core]
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.
July 8, 2020

Ok, this is tricky.

In order to use this convertToMultiSelect method you need to respect the output that their API is expecting and none available API have this by default;

The ideia is to use a Script Rest Endpoint that will return all components from a project with the expected output format:

https://gist.github.com/ItaloQualisoni/e663e7f6da3d3893fee37cb188d4cc28

You can test the rest endpoint by accessing the below url replacing the KEY with your project key.

http://JIRAURL/rest/scriptrunner/latest/custom/getComponent?projectKey=KEY

 

Having the Rest Endpoint working,  you will have to update your Behaviour initializer to consume our new API , see below example:

https://gist.github.com/ItaloQualisoni/29bb890f018d83ecfcdb7bb3e3c7434c

 

I've tested these 2 scripts with JIRA 8.6 and it worked :)

Jon Kocen
Contributor
July 9, 2020

The more I learn about ScriptRunner, the  more impressed I am with what I can accomplish in JIRA. I am very happy you all are part of the JIRA ecosystem.

Like # people like this

Suggest an answer

Log in or Sign up to answer