Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The SQL database has two tables called "Zone" and "Rules". Users are allowed to select a "zone_id" from the Zone table and use the "zone_id" as a foreign key to select the rules display all the rows associated with that " zone_id ". In the Zone tablein the Rules tables. Here, "zone_id" is the primary key in the Zone table and "Demog" is the foreign key in the Rules table. Please see below the structure of Zones and Rules tables.

...

Code Block
themeMidnight
{groovy:output=wiki}
import com.atlassian.renderer.v2.RenderMode
def choiceSql = "select distinct concat( zone_id,':', zone_id,':') from zone ;"
 
def choiceMacro = "{sql-query:datasource=yoga-sql|table=false} ${choiceSql} {sql-query}"
 
def choices = subRenderer.render(choiceMacro, context, RenderMode.suppress(RenderMode.F_FIRST_PARA))
 
def runMacro = """
{run:id=dynamic|autorun=true|replace=report:2010::select::${choices.replaceAll(" ","::")} }
{sql-query:datasource=yoga-sql|rowStyles= ,background-color:lightblue,}

select * from rules where demog = '\$report';

{sql-query}
{run}
"""
 
out.println runMacro
{groovy}


The end result would be as shown in the screenshot below.

Image Added

  1. The customer is asked to select a zone Id from the drop-down.
  2. Hit the Run button to generate the output
  3. The output shows the table results.
Note

Modify the SQL data source, table names, and columns as per the instance.

...