We are using Bob Swift's Run and SQL macros and trying to do something that seems would be pretty straight forward, however we are hitting a snag. The functionality we are trying is to use a run macro with form to obtain user input parameters. The parameters are passed into the SQL query to perform a select (dup check).
I would like to evaluate the sql reply inside the run macro and if we get a hit present a 'object exists' message, else if we do not get a hit - insert into the db with the user parameters and present a 'object inserted' message.
I have tried putting a groovy macro inside the run macro to drive the if/then but the run macro does not seem to like that. Has anyone done something similar? I know this has to be able to be done I am just missing something in front of my nose.
Bob answered my question on his site:
I think the best thing to do is to keep the logic isolated and simple. Create an SQL function in your database that does an update or insert. Similar to the answer to this question.
For anyone wanting to do something similar, you can define SQL functions in the database and then call them from the run macro using the sql macro - see example below:
{groovy|output=wiki}
import com.atlassian.renderer.v2.RenderMode def renderMode = RenderMode.suppress(RenderMode.F_FIRST_PARA)
// define domain list from database def domainSql = "select distinct(DOMAIN_NAME) , ':' , DOMAIN_NAME , ':' as domain from tbl_domains order by DOMAIN_NAME asc" def domainMacro = "{cache}{sql-query:datasource=custom_app_db_dev|table=false} ${domainSql} {sql-query}{cache}" def domains = subRenderer.render(domainMacro, context, renderMode)
//define systemarea list from database def systemareaSql = "select distinct(SSA_NAME) , ':' , SSA_NAME , ':' as systemarea from tbl_service_system_area order by SSA_NAME asc" def systemareaMacro = "{cache}{sql-query:datasource=custom_app_db_dev|table=false} ${systemareaSql} {sql-query}{cache}" def systemareas = subRenderer.render(systemareaMacro, context, renderMode)
//define runMacro variable to display the form
def runMacro = """
{run:id=addservice|autorun=false|requestActions = printresults|Heading=Service Information Form|titleRun=Add New Service|dateformat=yyyy-MM-dd|inputSize=75|replace=g1::?Name:group, serv::?Service name only. DO NOT add version information:text-required-end, g2::?Service Information:group, type::Type:select::BS:BS:FGS:FGS, dom::Domain:select::${domains}, ssa::Service System Area:select-end::${systemareas},desc::Description:textarea|keepRequestParameters = false}
{sql:datasource=custom_app_db_dev|table=false}
select SERVICEDUPCHECK('\$serv','\$type','\$dom','\$ssa','\$desc')
{sql}
{run}
"""
out.println runMacro
{groovy}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.