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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,456,674
Community Members
 
Community Events
176
Community Groups

Scriptrunner Custom Picker field Rest API

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

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

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();
}
}

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

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events