Forums

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

Retrieve data by REST API to select in a dropdown / search custom field

Ellen Beentjes
Contributor
October 3, 2018

We would like to receive a list of projects by Rest API and select one in a custom field. 

We have an API connection that returns a list of values.

Can I create a custom field that shows in a dropdown the list so I can select one and save it to the issue?

Any suggestions or similar integrations

2 answers

0 votes
Thomas Opiolka - codefortynine
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.
February 5, 2019

There is now a Jira cloud App called External Data for Jira Fields that allows to synchronise external data with a dropdown custom field.
You can connect your REST API as a data source and define how the dropdown custom field should be populated. From then on the dropdown will stay in sync with your REST API (new values will be created and missing ones disabled)

Hope this helps.

Best,

Thomas

Disclaimer: I'm the product manager of this App.

0 votes
mamer_atlassian
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 15, 2018

Hi Ellen,

The default drop down list by default requires pre-defined value. As your list is dynamic, it may be difficult to do that with a single list. There might be other ways to do it but a quick solution will be to use a drop down list and a read only text field. Here is an example:

1.  Create two custom fields, a drop down and a text field

2. Put the two fields on the Create Issue and Edit Issue screens

3. Put the text field in the view screen only

 4. Go to Settings > Custom fields > Edit the drop down field and put the following in the description field:

<script type="text/javascript">

//Get projects

var xhr = new XMLHttpRequest();
xhr.open("GET", "http://localhost:8081/rest/api/2/project", false);
xhr.send();
var obj = JSON.parse(xhr.responseText);
//Set dropdown field values
var list = document.getElementById("customfield_10800");

for (i = 0; i < obj.length; i++) {
var option = document.createElement("option");
option.text = obj[i].key;
list.add(option);
}

//Set the text field value to the selected project

AJS.$(document).ready(function() {
AJS.$('#customfield_10700').prop('readonly', true);

AJS.$('#customfield_10800').on('change', function() {
var project = $(this).val();
AJS.$('#customfield_10700').val(project);

});

//Dropdown lists require predefined values, set the selected value back to the default value submit button is clicked

AJS.$('#create-issue-submit').click(function() {
AJS.$('#customfield_10800').val('0');
});


AJS.$('#edit-issue-submit').click(function() {
AJS.$('#customfield_10800').val('0');
});

});
</script>

 

You will need to replace the custom field IDs with your own IDs.

Best Regards,

Muaamar Amer

Jarrod Moura
Contributor
December 12, 2019

This worked for me, thanks.

 

Any idea how to append to a label or component using javascript, instead of a text box?

Steven Cavanagh July 16, 2024

Wouldn't that throw cross site scripting errors? 

And is there a better option these days?

Nate Whitehead
Contributor
February 19, 2025

@Steven Cavanagh was thinking the same. Is there another method for solving this? Data Connections for JSM projects is so simple to use - is there a way of exposing those dropdowns to Software (now just "Jira") projects?

Suggest an answer

Log in or Sign up to answer