Versions Compared

Key

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

...

Section
Column

If the choices need to be more dynamic or the page is heavily used and you are concerned about dynamically using groovy on the page, then this is a better alternative. However, it does require a few more parts. The basic idea is to use the groovy code to generate a form page. The form page can be used directly or it can be included in another page. So, up to 3 pages are involved:

  • form page that will be automatically updated
  • generate page that administrators use to generate the form page
  • user access page that includes the form page

Steps

  1. Follow steps #1 - #5 as before
  2. Create a form page with a title of your choosing
  3. Create a generate page
    • Intended only for administrators or automation
    • Modify the following example script with your specifics including form page title
      Code Block
      {run2:titleRun=Update form page}
      
      {groovy}
      import com.atlassian.renderer.v2.RenderMode
      
      def renderMode = RenderMode.suppress(RenderMode.F_FIRST_PARA)
      
      def choiceSql = "select distinct(year) || ':' || 'Report ' || year || ':' as choice from reports order by choice desc"
      
      def choiceMacro = "{sql-query:datasource=testDS|table=false} ${choiceSql} {sql-query}"
      
      def choices = subRenderer.render(choiceMacro, context, renderMode)
      
      def runMacro = """
      {run:id=dynamic|autorun=true|replace=report:2010::select::${choices}}
      {sql-query:datasource=testDS}
      select * from reports where year = \$report
      {sql-query}
      {run}
      """
      
      def title = context.getPageTitle() + " - form"
      def spaceKey = context.getSpaceKey()
      
      def page = pageManager.getPage(spaceKey, title)
      
      if (page != null) {
      page.setContent(runMacro)
      println "Form page '${title}' updated."
      } else {
      println "Page '${title}' not found."
      }
      
      {groovy}
      
      {run2}
      
  4. Use the generate form button to update the content of the form page
  5. Optionally, add autoRun=true so automation can render the page on a schedule to keep the form current automatically
Column

Info
titleSpecial characters in choice text

If data from the query contains embedded commas or colons, more care is required in the scripts to provide the appropriate quoting of the values.