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

This widget could not be displayed.

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

http://docs.atlassian.com/jira/REST/latest/#id206716

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 Sign up to answer
Community showcase
Posted Thursday in United States

Local Atlassian Research Workshop opportunity on Sep. 28th

We're looking for participants for another workshop at Atlassian! We need Jira admins who have interesting custom workflows, issue views, or boards. Think you have a story to sh...

71 views 0 0
View post

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