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

This widget could not be displayed.

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
getFieldById("summary").convertToMultiSelect([
    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"?

            textField.convertToSingleSelect([
                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
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Published Jul 25, 2018 in Marketplace Apps

Jira Cloud and Bitbucket Cloud Integration with Microsoft Teams

One of the newest products in the Microsoft family - Microsoft Teams,  is a chat-based hub for teamwork that integrates all the people, content, and tools your team needs to be more engaged and ...

717 views 0 3
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