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:

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}
insert into table1 (name, type) values (?, ?)
out.println runMacro



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}
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 {


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:

	Some scripts
				Some More scripts



 Any help is greatly appreciated!

1 answer


Did you get anywhere with this?

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Jul 10, 2018 in Confluence

We want to see the templates you've created in Confluence!

Hi Community, Jessica here from the Confluence Product Marketing team!  July’s community challenge is all about sharing pictures  — and as an extension of our first post on what ...

606 views 20 11
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