Hi,
Does anyone knows how to create a custom/user macro using RUN plugin & groovy script, so that I can call macro on each page.
Here is the code that I'm trying to create Macro
{run:replace=a1::hidden value:Hidden description:hidden, g1:$current_user_id::hidden, g2:$page_title::hidden, g3:$page_id::hidden, r1::I have read this page:radio::1:Yes} {groovy:output=wiki} import com.atlassian.renderer.v2.RenderMode def renderMode = RenderMode.suppress(RenderMode.F_FIRST_PARA) def choiceSql = "SELECT distinct(page_id) FROM test_Wiki_Read_Status WHERE page_id ='$g3' AND ad_user = '$g1'" def choiceMacro = "{sql-query:datasource=testDS|table=false} ${choiceSql} {sql-query}" def choices = subRenderer.render(choiceMacro, context, renderMode) if(choices !=''){ def runMacro1 = """ {sql-query:datasource=testDS} UPDATE test_Wiki_Read_Status SET read_status = '$r1' WHERE page_id = '$g3' AND ad_user = '$g1' {sql-query} """ out.println(runMacro1) }else{ def runMacro = """ {sql-query:datasource=testDS} INSERT INTO test_Wiki_Read_Status (ad_user, page_id, page_title, read_status) VALUES('$g1','$g3','$g2','$r1') {sql-query} """ out.println(runMacro) } {groovy} {run}
I believe you need to create a user macro in the normal way and then use render support:
#set ($runMacro = ...) $action.getHelper().renderConfluenceMacro($runMacro)
That is the detail for the user macro implementation. You just need your specific run macro text string from your question copied into the variable. You are rendering that macro in the user macro.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have tried as you said but I'm getting below error message: "Error rendering macro 'pagereadstatus' : Error occurred rendering template content" Here is the code that I'm using #set($runMacro2 = '{run:replace=a1::hidden value:Hidden description:hidden, g1:$current_user_id::hidden, g2:$page_title::hidden, g3:$page_id::hidden, r1::I have read this page:radio::1:Yes} {groovy:output=wiki} import com.atlassian.renderer.v2.RenderMode def renderMode = RenderMode.suppress(RenderMode.F_FIRST_PARA) def choiceSql = "SELECT distinct(page_id) FROM AC_Wiki_Read_Status WHERE page_id =\'$g3\' AND ad_user = \'$g1\'" def choiceMacro = "{sql-query:datasource=testDS|table=false} ${choiceSql} {sql-query}" def choices = subRenderer.render(choiceMacro, context, renderMode) if(choices !=''){ def runMacro1 = """ {sql-query:datasource=testDS} UPDATE AC_Wiki_Read_Status SET read_status = \'$r1\' WHERE page_id = \'$g3\' AND ad_user = \'$g1\' {sql-query} """ out.println(runMacro1) }else{ def runMacro = """ {sql-query:datasource=testDS} INSERT INTO AC_Wiki_Read_Status (ad_user, page_id, page_title, read_status) VALUES(\'$g1\',\'$g3\',\'$g2\',\'$r1\') {sql-query} """ out.println(runMacro) } {groovy} {run}') $action.getHelper().renderConfluenceMacro($runMacro2) Please help me with this
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am sorry, debugging your user macro is outside our scope for support. Have you considered using a simpler approach using a page include instead of a user macro?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, there normally isn't a problem with most macros.
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.