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

Peter Csiba July 9, 2012

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 votes
Answer accepted
Jobin Kuruvilla [Adaptavist]
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 9, 2012

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

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

Peter Csiba July 9, 2012

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

Peter Csiba July 10, 2012

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.

Jobin Kuruvilla [Adaptavist]
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 10, 2012

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

Peter Csiba July 10, 2012

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
TAGS
AUG Leaders

Atlassian Community Events