You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
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
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
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();
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 value, label, 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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.