Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Scriptrunner Custom Picker field Rest API

Dominykas Šmičius February 9, 2022

Hello,
please help me to understand how i can make a multi select field with custom picker and with options from rest api. I spent few days but cant understand why it not working as expected.
I have in REST endpoint written api, who return values in json.
I attached print screens to be clear what i'am trying to do

Where ismy mistake?

Thanks in advance

1.png2.png3.png

1 answer

Suggest an answer

Log in or Sign up to answer
0 votes
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 9, 2022

Hi @Dominykas Šmičius

Could you please share the code you are using to create your REST Endpoint in text format?

This is so that I can review it and provide some feedback.

Thank you and Kind Regards,

Ram

Dominykas February 9, 2022

Hi @Ram Kumar Aravindakshan _Adaptavist_ 

I just want to warn you that this is just an example with project extraction. My goal has other meanings. I want to understand how it works.

-----

import com.atlassian.jira.component.ComponentAccessor;
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate;
import groovy.json.JsonBuilder;
import groovy.transform.BaseScript;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.core.Response;

@BaseScript CustomEndpointDelegate delegate;

JIRA_All_projects{ queryParams, body, HttpServletRequest request ->

def id = request.getParameter("id");
def inputValue = request.getParameter("inputValue");
def projectManager = ComponentAccessor.getProjectManager();

def projects = projectManager.getProjectObjects();
def jsonBody = [];

if(id){
jsonBody = projects.collect {
[
value:it.key,
label:it.name
]
}.find{it.get("value") == id}

return Response.ok(new JsonBuilder(jsonBody).toString()).build();

}else if(inputValue){
jsonBody = projects.collect {
[
value:it.key,
label:it.name
]
}.findAll{it.get("value").contains(inputValue)}

return Response.ok(new JsonBuilder(jsonBody).toString()).build();
}else{
jsonBody = projects.collect {
[
value:it.key,
label:it.name
]
}
return Response.ok(new JsonBuilder(jsonBody).toString()).build();
}
}

Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 11, 2022

Hi @Dominykas Šmičius,

From a high level, what you are trying to do is you are trying to pass the options added in a REST Endpoint you have created into the Custom Picker.

If you want to pass the value to the custom picker, you will need three elements, i.e. the valuelabel, and the html parameters. However, it appears that you are only providing the value and label. Hence, this will not work.

If you refer to the JSON example on this ScriptRunner Documentation, you will notice that all three parameters mentioned above are added.

Also, when using the HtmlBuilder to invoke your REST Endpoint, in the HtmlBuilder's constructor, you should only include your base URL, for example, http://jiraserver.com. The following parameters of your URL should be included in the URI path.

You can refer to an example from the Adaptavist Library for more information. You can see in the library example provided instead of using the HttpBuilder, you can use the RESTClient, a child class of the HttpBuilder and how the URI path is added separately from the main URL.

Thank you and Kind Regards,

Ram

TAGS
AUG Leaders

Atlassian Community Events