How to generate choice values using SQL?


Can anyone help me to generate choice values using SQL, I tried with the example which is there in the documentation but that is not working for me.

Please find below code and Link I have referred.


import com.atlassian.renderer.v2.RenderMode

def renderMode = RenderMode.suppress(RenderMode.F_FIRST_PARA)

def choiceSql = 'select first_name from AC_users'

def choiceMacro = '{sql-query:datasource=acpdatabaseDS|table=false} ${choiceSql} {sql-query}'

def choices = subRenderer.render(choiceMacro, context, renderMode)


{sql-query:datasource=acpdatabaseDS} select * from AC_users {sql-query} {run}

If I execute the above code, I'm getting out put like below

1 answer

First, I always recommend when doing more complex things to break it down and make sure each part works as expected, then put it together to get everything working together. In this case

  1. Get your run macro working with 2 or 3 item select
  2. Run your query separately and make sure it produces the right string
  3. Run groovy with *output=html* initially to ensure that the result looks like the right markup from your earlier steps or to debug things if it doesn't work. You can always copy/paste into wiki macro to see the rendering.

Specifically to your example here:

  1. Your query isn't producing a colon (:) separated list needed by the run macro. Probably you want: first_name || ':'
  2. Your choiceMacro is being set to a literal string. Use double quotes (") to get ${choiceSql} evaluated
  3. You need to use out.println(...) to produce the output data

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Jul 10, 2018 in Confluence

We want to see the templates you've created in Confluence!

Hi Community, Jessica here from the Confluence Product Marketing team!  July’s community challenge is all about sharing pictures  — and as an extension of our first post on what ...

783 views 23 12
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you