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,559,469
Community Members
 
Community Events
184
Community Groups

Behaviour and external API does not return correctly

serge calderara
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Sep 24, 2021

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

85n6fGXLB8.png

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

2DJku6rAdg.png

Any idea ?

I am struggling this for a full week now and I am stuck, hoping you can help

regards

 

1 answer

0 votes
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Sep 24, 2021

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

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events