How to generate choice values using SQL?

Hi,

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.

https://bobswift.atlassian.net/wiki/display/RUN/How+to+generate+choice+values+using+SQL

{groovy:output=wiki}

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)

{run:autorun=true|replace=Name:?Select:select::${choices}}

{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 Nov 29, 2018 in New to Confluence

How to use Confluence Cloud for stakeholder management

Most of us don’t need much convincing that stakeholder management is important. It just makes sense that keeping everyone in-the-know on projects and assigning clearly defined roles is key to having ...

1,054 views 0 5
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