Dear all,
I am trying to build a behaviour which convert a text field in a select list box by collecting data from an exteranal API.
For that I follow the samples provided in this link below :
Select List Conversions (adaptavist.com)
I have for that created a simple REST API call which collect VM information from Azure and which return the following sample data from POSTMAN
From my custom Rest endpoint, I need to return the *tags list items* in order to be visible into the Select List field of my behavior
The issue I met is that I do not know, or at least it is not so clear from sample on the way I should format the return response from the API in order that behavior gets the data
In my sample snipet code below, I need to return, as in the sample, a New JsonBuilder object based on my json return by the API but I could not get the correct syntax to replace in ???????? in order that my field slection contains items *com, aem, dispatcher* from tags element of my original return json above
Any idea ?
I am struggling this for a full week now and I am stuck, hoping you can help
regards
The select conversion method need the JSON in very specific format.
So you'll need to prepare a return object with that format.
Based on what you provided, I'm expecting the vmInfo object returned by httpBuilder.request to look something like this (as you would deeclarie it in groovy)
[
name:'dummy',
location:"don't care",
tags:[
app:'appname',
product:'aem',
type:'dispatcher']
]
So if I start with building a replacement variable with this data, I can use that to construct the output object
def vmInfo = [name:'dummy', location:"don't care", tags:[app:'appname', product:'aem', type:'dispatcher']]
//we're only interested in the tags ... I've opted to include both tag key and value sepearated by colon, but you can adjust that format
def tags = vmInfo.tags.collect{k,v-> "$k : $v"}
//normally, the query should come from your rest api with
//def query = queryParams.getFirst("query") as String
// but I used this for testing
def query = 'prod'
//this is the object we need to return
def singleSelectRet = [
items : tags.collect{tag ->
[
value: tag,
label: tag,
html: tag.replaceAll(/(?i)$query/) { "<b>${it}</b>" }
]
},
total : tags.size(),
footer : "Select a tag"
]
return Response.ok(new JsonBuilder(singleSelectRet).toString()).build()
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.