Put components from a specific project as pickable options in a custom field

I am trying to create a custom field which functions like a Component field from a specific project. That means I will be able to pick the components from that project and add them to this custom field. I tried something like this under Behaviours/Initialiser Function:

getFieldByName("Linked Components").convertToMultiSelect([
    ajaxOptions: [
        url : getBaseUrl() + "/rest/api/2/project/10110/components",
        query: true,
        formatResponse: "general"

It did not work, and I can't seem to find any documentation on how ajaxOptions really works.

1 answer

The rest api you have chosen doesn't return the components in the right "shape" as required by the "general" formatted.

So you need to write your own endpoint - which I have done here: https://gist.github.com/jechlin/4c9817846ed98f025053003846541a6f

Then I changed the initialiser to:

def projectId = issueContext.projectId
    ajaxOptions: [
        url : getBaseUrl() + "/rest/scriptrunner/latest/custom/components?projectId=$projectId",
        query: true,
        formatResponse: "general"

Note I am passing the project ID to get the components from, using the project for the current issue, but it need not be.

Jamie, I have a similar question.


Is it possible to convert text field to user picker using standard REST Endpoint? In other words, are there other options for formatResponse exept "general" and "issue"?

                ajaxOptions: [
                    url: getBaseUrl() + "/rest/api/latest/user/picker",
                    query: true,
                    data: [
                        showAvatar: true,
                    formatResponse: "?",
                css: "max-width: 500px; width: 180px",

Possibly... can't remember. Why don't you just use a user custom field?

Jamie, thank you for your reply.

I have two fields:

  1. Owner type: select list field with two options - "Company" and "Employee"
  2. Owner: text field that I would like to convert to Single Select with options list that depends on Owner type field

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Mar 13, 2019 in Marketplace Apps

Marketplace Spotlight: Marketing apps for Confluence to keep your teams working on the same page


247 views 0 6
Read article

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