Running a Groovy script inside of a Run macro inside of another Groovy script

OK, here is a totally off the wall question, but we've hit a wall with some functionality that we need to figure out.

We've taken Bob swifts scripting examples and have been able to populate form fields with data derived from preset queries and then we've been able to insert, update, delete or simply view data using the SQL plugins inside of the Run macro. Example:

{groovy:output=wiki}
import com.atlassian.renderer.v2.RenderMode
def renderMode = RenderMode.suppress(RenderMode.F_FIRST_PARA)
def getSql = "select * from table where x = y"
def getMacro = '{sql-query:datasource=testdb|table=false} ${getSql} {sql-query}"
def get = subRenderer.render(getMacro, context, renderMode)

def runMacro = """
{run:id=test|autorun=false|replace=name::Name, type::Type:select::${get}|keepRequestParameters = true}
{sql:datasource=testdb|table=false|p1=\$name|p2=\$type}
insert into table1 (name, type) values (?, ?)
{sql}
{run}
"""
out.println runMacro
{groovy}

 

 

However, we need to go a little deeper with our functionality. We need to be able to create checks and display some messages based on the query results. for example, if someone completes a form to insert data in a table, we want to be able to run some scripts to check the db first before inserting the data.

Now, we've been able to use a Run macro  with Groovy code inside of it to take the values and check the db tables. Example:

{run:id=test|autorun=false|replace=name::Name, type::Type:select::${get}|keepRequestParameters = true}
{groovy}
def checkSql = "{select * from table where name = '\name' and type = '\$type'}"
def checkMacro = "{sql-query:datasource=testdb|table=false} ${checkSql} {sql-query}"
def check = subRenderer.render(checkMacro, context, renderMode)        
if (check == "")
        {
               println("This information does not exist.")
         } else {
               println(checkMacro)
        }
{groovy}
{run}

 

What we need to be able to do is combine the 2 so that we can use the variables obtained from the main groovy script in the run macro and then use other groovy scripts inside that same run macro. But, I have no idea how to do this or if there are other options out there.

 

It's like I need to have a combination of the macros:

{groovy}
	Some scripts
		{run}
			{groovy}
				Some More scripts
			{groovy}
		{run}
{groovy}

 

 

 Any help is greatly appreciated!

1 answer

This widget could not be displayed.

Thomas,

Did you get anywhere with this?

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Monday in Confluence

Why start from scratch? Introducing four new templates for Confluence Cloud

Hi my Community friends!  For those who don't know me, I'm a product marketer on the Confluence Cloud team - nice to meet you! For those of you who do, you know that I've been all up in your Co...

253 views 2 4
Join discussion

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