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

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

Dong Park November 1, 2019

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

Suggest an answer

Log in or Sign up to 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.
November 2, 2019

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"}"} 
Dong Park November 4, 2019

That work, thanks!

TAGS
AUG Leaders

Atlassian Community Events