Hi,
I would like to add a form as a template in Confluence.
The input of the form should be used as input parameters to a jira gadget.
Is this possible?
Best regards, Therese
I achieved this by creating a user macro as a wrapper for the jira gadget i wished to use as such:
## Macro name: version-issues ## @param Project:title=project|type=string|required=true|desc=Project Key ## @param Version:title=version|type=string|required=true|desc=Fix Version <ac:macro ac:name="jiraissues"> <ac:parameter ac:name="title">All Resolved Issues</ac:parameter> <ac:parameter ac:name="renderMode">static</ac:parameter> <ac:parameter ac:name="columns">type,key,summary,reporter,resolution,component</ac:parameter> <ac:parameter ac:name="url">http://jiraurl:8080/sr/jira.issueviews:searchrequest-rss/temp/SearchRequest.xml?jqlQuery=project+=+"$paramProject"+AND+fixVersion+=+"$paramVersion"&lt;/ac:parameter&gt; </ac:macro>
This example creates a jira issues list for a given project and fixversion
Then you can put this macro in your template.
I'd like to note that I haven't figured out a way to pass a template parameter into the macro parameters.
Thank you for answering that fast :-)
So are the project and fix version added by the end user in a confluence form?
Are the parameters confluence variables?
They will be parameters in the macro. As I said above, I still don't know how to have the user enter them as template-level variables. The user needs to edit the macro once the templates generates the page, but at least it simplifies filling in the parameters of the macro. They will be presented with a macro edit screen with just those parameters.
This was really helpful for me. I was able to write a JIRA issues wrapper that just took in the fixVersion for the $body. I finally figured out how to have the fixVersion be a variable passed to all the macros on the page (I have several) that rely on it.
I had to change the Macro Body Processing to Rendered and have @noparams set. So when I created the template and added the macro, I could add the $fixVersion variable to the macro in the template. The $fixVersion is set at the top of my page and once set, all the macros are updated with that data. Thus, the $fixVersion becomes the $body in the macro.
So I guess if you only have 2 params, if you just pass them into the body, you should be able to parse them from $body and assign them to the paramX variables in your macro. I haven't seen any other way to pass variables to the params in the pop-up dialog box.
Roxanne can you give a sample of what you did with the $body to make it work? Do you have a code sample. I'm fairly new to Velocity, Atlassian macros and the such. Did you just put the $fixVersion directly inside the text block of the macro? Did you just use $body directly in your JIRA search query?
I have reconstructed this somewhat - for whom might be interested in this.
The User macro will contain the storage representation of all the macros you want to render with the variable.
Macroname: applytemplatevarType: renderedTemplate:
## @noparams<ac:structured-macro ac:name="panel"> <ac:parameter ac:name="bgColor">#72bc72</ac:parameter> <ac:parameter ac:name="titleBGColor">#00a400</ac:parameter> <ac:parameter ac:name="title">$body</ac:parameter> <ac:parameter ac:name="borderStyle">dashed</ac:parameter> <ac:parameter ac:name="borderColor">blue</ac:parameter> <ac:parameter ac:name="titleColor">white</ac:parameter> <ac:rich-text-body> <p>A formatted panel</p> </ac:rich-text-body></ac:structured-macro>
Design a template with a single variable - you can call it whatever you like. insert the macro above and put the variable inside the body as well. You should now have the variable both at the top of the page (or at least outside the macro too) AND inside the body of the applytemplatevar macro.
Now create page using this template. You will be prompted with entering the variable as usual. The create page screen will complain about broken macros because the simple example above does not have a value for the body initially. Preview the page and see that the panel shows with the title entered. Now what I am wondering is:
1) how to get more variables2) how to apply this to macros entered on the edit page, so any macro can be used.(Answer edited to format nicely)
I figured since we solved this recently, i would add our official solution to this request which allows to inject any number of variables into any JQL filter in a Confluence Template. Below is the how-to as well as some usage notes i wrote for our company:
First we start out with determining the current syntax of the JQL Issues/Filter macro in confluence:
Copy the JIRA Issue/Filter macro syntax to a text editor, e.g.
<p> <ac:structured-macro ac:macro-id="5a45704b-a904-4440-bdc0-da68a22d5802" ac:name="jira" ac:schema-version="1"> <ac:parameter ac:name="server">JIRA</ac:parameter> <ac:parameter ac:name="columns">key,summary,type,created</ac:parameter> <ac:parameter ac:name="maximumIssues">20</ac:parameter> <ac:parameter ac:name="jqlQuery">assignee = abarylak and resolution is EMPTY </ac:parameter> <ac:parameter ac:name="serverId">c8001771-0b52-30e0-9703-562a2820710f</ac:parameter> </ac:structured-macro></p>
Then we need to use the above syntax (a little modified) and use that for our macro.
Results are as follows:
## Macro title: JQL Filter Allowing Variables## Macro has a body: Y## Body processing: Rendered## Output: JIRA Issues/Filter Macro w/ injected variables#### Developed by: Adam Barylak## Date created: 2016-05-27## Installed by: Adam Barylak## This macro will prompt for max number of rows and the column option, then the body will require the JQL with injected variables## @param maxRows:title=Max Rows|type=int|required=true|default=20|desc=Enter the max rows, anything above 1000 will only display 1000 rows.## @param columns:title=Columns|type=string|required=true|default=key,summary,type,status,assignee|desc=Enter the columns you want returned. Must be separated by commas, all lowercase, and no quotes. e.g. key,summary,assignee,test author,reporter #set ($body = $body.replaceAll("\Q<p>\E",""))#set ($body = $body.replaceAll("\Q</p>\E",""))#set ($body = $body.replaceAll("\Q<span>\E",""))#set ($body = $body.replaceAll("\Q</span>\E",""))#set ($body = $body.trim())<p><ac:structured-macro ac:name="jira" ac:schema-version="1"> <ac:parameter ac:name="server">JIRA</ac:parameter> <ac:parameter ac:name="columns">$paramcolumns</ac:parameter> <ac:parameter ac:name="maximumIssues">$parammaxRows</ac:parameter> <ac:parameter ac:name="jqlQuery">$body</ac:parameter> <ac:parameter ac:name="serverId">c8001771-0b52-30e0-9703-562a2820710f</ac:parameter></ac:structured-macro></p>
Create the macro in confluence with the following options or similar (change as needed):
Hopefully this helps others accomplish this same task. This ends up being really useful if you need to repeat a bunch of JQL filters for different things on different pages in Confluence and you don't have to store these filters as saved filters in JIRA either.
Adam, absolutely excellent write-up and solution. It works straight out of the box, once the "serverId" line is exchanged with the one for the local server.
If I had 10 points to give you would get them.
Edit:
I have edited Adam's answer above to include removing <span></span> tags as well. I found that a body like this:
project=TO and sprint in ("Sprint 1", "Sprint 2")
ended up as
project=TO and <span> sprint in ("Sprint 1/1", "Sprint 1/2") </span>
That obviously does not compute. Removing the <span> does the trick.
Thanks for the update. When it injects those tags is probably one of the reasons we sometimes just have to re-type the entire jql string by hand and why I put the "If all else fails" section in the guide for our users. I just didn't have the time to investigate further. I will be adding that to my macro as well. Thanks for looking into that.
Hi Adam,
Thank you so much for the solution.
I have one more question: How to display JIRA link on the top of Confluence page as it is displayed when using original JIRA issue macro?
shot_109.bmp
I have transformed your macro a little bit and that's what I got:
<ac:structured-macro ac:name="jiraissues" ac:schema-version="1"> <ac:parameter ac:name="server">JIRA</ac:parameter> <ac:parameter ac:name="count">false</ac:parameter> <ac:parameter ac:name="maximumIssues">1</ac:parameter> <ac:parameter ac:name="serverId">JIRA_server_ID</ac:parameter> <ac:parameter ac:name="atlassian-macro-output-type">INLINE</ac:parameter> <ac:parameter ac:name="key">$body</ac:parameter> </ac:structured-macro>
And I can't see the link to JInk to JIRA on a top of the page(
Thank you in advance.
This is very helpful. Is there a way to display the total issue count of the query through this macro? Any help would be great.
If you search this page for "count", that should to the trick:
<ac:parameter ac:name="count">true</ac:parameter>
Is there a way to convert the output of this macro to a string or integer? Example: turn "86 issues" link into just "86". Would make this macro very useful for charts.
Is this restricted to server instance or can this be done on cloud?
The "Confluence Source Editor" isn't available for Cloud :-(
Is there a true solution when the admin group doesn't want to support user macros at all ? I feel this hasn't been answered properly yet. It's a great workaround, but not useful for big groups that are very restrictive.
It looks like you're new here. Sign in or register to get started.