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 votes
Answer accepted

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:

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):

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted yesterday in United States

From Atlassian: Confluence Security Advisory - 2019-03-20

Atlassian released a security advisory on 3/20/2019.  The full advisory is here: In a nutshe...

22 views 0 1
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