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

Mads Stavang February 21, 2017

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

3 votes
JamieA
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.
February 22, 2017

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.

Serhii Riabovil March 22, 2017

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",
            ])

JamieA
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.
March 28, 2017

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

Serhii Riabovil June 1, 2017

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

Atlassian Community Events