• Community
  • Questions
  • Gadget User Preference - select from dynamic list. What is the best way?

Gadget User Preference - select from dynamic list. What is the best way?

To be more specific: I want an user pref where the user is able to choose from all available custom fields.

Gadget userpref specification defines only static enum. So, one of the easier solutions can be getting the enum (config) XML code with custom REST GET request similary as described at j-tricks.

Or is there any easier solution?

1 answer

1 accepted

0 vote

Using REST GET is the only way possible. There is already an existing method btw!


Thank you for the speedy answer :) I will try it tomorrow at sure.

Okay, it is almost working. But the select field in the configuration of the gadget requires options as array of {label, value} pairs and REST "/rest/api/2/field" returns array of issue field descriptors [id, name, custom, ...].

So, I tried to write some JavaScript code to add label and value fields to the array. Then I realized that ajaxOptions are executed only when I click on the select field in my browser -- so it seems there is no way to modify the returned REST resource on the client side.

A tried to get the array of fields directly:

var opt = jQuery.ajax("/rest/api/2/field");

But Jira says 403: Forbidden.

So the only possibility seems to be to write my own REST GET method for retrieveing the issue field list as label - value pairs. Am I right?

Thank you in advance.

Actually, you should be able to manipulate the REST output on the client side itself. I don't think you need a separate method that returns array!

You will find an example of projects here: https://developer.atlassian.com/display/JIRADEV/Plugin+Tutorial+-+Writing+Gadgets+for+JIRA

Okay, I have found it finally. It should be possible to specify a callback function in the jQuery ajax request (code is not tested):

ajaxOptions: function() {
  return {
    url: "/rest/api/2.0/field",
    settings: [
        key: "success",
	value: function(data, textStatus, jqXHR){}

In the meanwhile I have implemented my custom REST request/response for getting the issue fields (this way it should be more flexible as I have an access to all jira functions). Next time I will try this way.

Thank you Jobin for the supervision!

More for the jQuery beginners (as I): http://api.jquery.com/jQuery.ajax/

Suggest an answer

Log in or Join to answer
Community showcase
Louis De Jaeger
Posted yesterday in Off-topic

Friday fun: your best joke

Hi all Lets make this Friday fun really fun and post one (or more) of your best jokes! The joke can be about an Atlassian product, or just a really fun joke you want to share! I’m not the best j...

106 views 5 2
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