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,366,304
Community Members
 
Community Events
168
Community Groups

ScriptRunner REST Endpoints & Json (combining two elements into one)

Hi,

I got this sample from here, https://scriptrunner.adaptavist.com/4.3.5/jira/behaviours-conversions.html

Code snippet from the url :

def repoNames = repos["items"]*."full_name" 
rt = [

items:
repoNames.collect { String repo ->
[

value:
repo,
html : repo.replaceAll(/(?i)$query/) { "<b>${it}</b>" },
label:
repo,
]
},

total:
repos["total_count"],
footer:
"Choose repo... (${repoNames.size()} of ${repos["total_count"]} shown...)"
]

 Json:

"id": 76954504,
      "node_id": "MDEwOlJlcG9zaXRvcnk3Njk1NDUwNA==",
      "name": "react-tetris",
      "full_name": "chvin/react-tetris",
      "private": false,
      "owner": {

As you can see it's getting the "full_name" but I want to combine let say "full_name" and "node_id".   So the output would look like "chvin/react-tetris  MDEwOlJlcG9zaXRvcnk3Njk1NDUwNA=="  Does anyone know how I can achieve this from the code?  

 

Thanks!

1 answer

0 votes

This line does an implicit collection of all the "full_name" from all the items (that's what the * does).

def repoNames = repos["items"]*."full_name" 

So instead, just do your own collection:

def repoNames = repos["items"].collect{"${it."full_name"} ${it."node_id"}"} 

That work, thanks!

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events