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- Follow steps #1 - #5 as before
- Create a form page with a title of your choosing
- 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}
|
- Use the generate form button to update the content of the form page
- Optionally, add autoRun=true so automation can render the page on a schedule to keep the form current automatically
|