Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to generate choice values using SQL?

SKR December 23, 2013

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

0 votes
Bob Swift
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 23, 2013

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
TAGS
AUG Leaders

Atlassian Community Events