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
Community showcase
Published Mar 12, 2019 in Confluence

Confluence Admin Certification now $150 for Community Members

More and more people are building their careers with Atlassian, and we want you to be at the front of this wave! Important Dates Start the Certification Prep Course by 2 April 2019 Take your e...

1,621 views 4 13
Read article

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