Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to properly convert single line text field to single select field.

Lulzim Bulica April 12, 2018

I need a single select custom field that contains the names of the project names in the Jira instance. There already exists a project picker but is not yet supported in the customer portal, thing that is a MUST for me.

What i have done so far: 

  • Created a Rest Endpoint that returns all the project names
@BaseScript CustomEndpointDelegate delegate
getProjects () { MultivaluedMap queryParams, String body,HttpServletRequest request ->

def projectList = ComponentAccessor.getProjectManager().getProjectObjects()
def projects = []

for(String prName : projectList.name){
projects.add(prName)
}


return Response.ok(JsonOutput.toJson(projects)).build()
}

//Works checking with Postman!
  • Created a behaviour on the initializer 
def test = getFieldByName("TEST")

test.convertToSingleSelect([
ajaxOptions: [
url : getBaseUrl() +"/rest/scriptrunner/latest/custom/getProjects",
type: "GET",
dataType: 'json',
query: false, // keep going back to the sever for each keystroke
minQueryLength: 5,
keyInputPeriod: 500,
data : [
label : "Pick a Task in project",
],
formatResponse: "general",

],

css: "max-width: 500px; width: 500px",
])

 

The problem is that when i go to the converted single select customfield i can not see the results. Any idea?

1 answer

1 accepted

0 votes
Answer accepted
Lulzim Bulica April 13, 2018

The problem was that in the rest Endpoint i was sending a simple list, that could not be read from the Javascript on the behaviour. So in the Rest endpoint i added this code : 

 fullList = [
items: projects.collect {
[
value: it,
html : it,
label: it,
]
},
]

return Response.ok(new JsonBuilder(fullList).toString()).build()

And it Worked!!!!!

Kyrylo Filipenkov July 25, 2018

@Lulzim Bulica Hello!

Can you show all code for me?

Really need, I will be very grateful.

Thank's.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events