Would like to get a value from a table to insert it into other macros
Asked by Guillaume Lorquet:

Hi,

I would like to know if it's possible to get the value from a place in a page (title, page properties, table...) and update others macros with this value (example : Jira macro).

Usage : I use Confluence for a dev team and we use in differents places Jira macros with always the same key. So instead of repeat the key number in each macro, I would like to create a template with a wizard and when we create the page, we insert the jira key in a single place, insert informations at the differents others places and then when I publish my page, the macro will show the correct information based on the key introduce in a single place.

In advance, thx for your help.


Answers:
author: Dominic Lagger
body: Hi [@Guillaume Lorquet](/t5/user/viewprofilepage/user-id/1291134)

We had to find a solution for a similar problem. We have more than 10 JIRA filters for checking our release. And on each of these filters, we have to change the "fixVersion" every single time, we release, in more than 10 JIRA macros...

So we made a user macro, where you just have to *search \& replace* the "fixVersion".

The user macro looks like this:

```
## Macro title: JQL Query in Body
## Macro has a body: Y
## Body processing: Rendered
## Output: JIRA Issues based on Jira Macro
## User Macros laufen auf der Apache Velocity Engine
## http://velocity.apache.org/engine/1.7/user-guide.html
##
## Modified:


## This macro can be used with injected template-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=type,key,summary,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 
## @param displayJQL:title=Display JQL|type=boolean|required=true|default=false|desc=Displays the JQL in an Info Box under the Result Table
#set ($body = $body.replaceAll("&quot;<p>","&quot;"))
#set ($body = $body.replaceAll("</p>&quot;","&quot;"))
#set ($body = $body.replaceAll("\Q<p>\E"," "))
#set ($body = $body.replaceAll("\Q</p>\E"," "))

#set ($body = $body.replaceAll("&quot;<span>","&quot;"))
#set ($body = $body.replaceAll("</span>&quot;","&quot;"))
#set ($body = $body.replaceAll("\Q<span>\E"," "))
#set ($body = $body.replaceAll("\Q</span>\E"," "))

#set ($body = $body.replaceAll("&quot;<pre>","&quot;"))
#set ($body = $body.replaceAll("</pre>&quot;","&quot;"))
#set ($body = $body.replaceAll("\Q<pre>\E",""))
#set ($body = $body.replaceAll("\Q</pre>\E",""))

#set ($body = $body.replaceAll("\Q<br/>\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">ff94f833-c264-3d1f-a236-7bdb5d13106c</ac:parameter>
</ac:structured-macro>
</p>

#if ($paramdisplayJQL=="true")
<ac:structured-macro ac:macro-id="94f6dacf-19a6-4679-ab0b-4052266a6b47" ac:name="info" ac:schema-version="1">
<ac:rich-text-body>
<p>$body</p>
</ac:rich-text-body>
</ac:structured-macro>
<br/>
#end
```

So you can set your JQL and it's shown in the edit mode. Therfore you just have to search \& replace your issue number.

Hope this helps.

Regards, Dominic


author: Shannon S
body: Hello Guillaume,

Thank you for contacting us.

Variables can be set only on a specific template, but you can't re-use that variable elsewhere.

Can you help me to understand what you're attempting to do exactly? From my understanding, you want to place the same Jira macro over and over again? It might be easier for you to create a search filter on the Jira end, and that way, when you go to insert the Jira issues macro, you can just recall the same filter.

Let me know if you have any questions about that.

Regards,

Shannon

comments: author: Guillaume Lorquet
body: Hi [@Shannon S](/t5/user/viewprofilepage/user-id/510046)

Thanks for your feedback.

My goal is to create a page with Jira table based on differents JQL and where the information are differents :

1. Jira Macro as "Single issue" : Based on JQL "KEY = KEY-111" and content key, summary and status.
2. Jira Macro as "Table" : Based on JQL "KEY = KEY-111" and content description of the issue.
3. Jira Macro as "Table" : Based on JQL "parent = KEY-111" and content description of the issue.

So, I would like to insert in a place the "KEY-111" and then all the different macro will be automatically populated at page creation.

I wanted to use template, insert variable and use them in the "Jira macros".

Example in print screen :

1. Create a page from a template.
2. Insert the issue key in a variable
3. The table is filled based on JQL in the macro that get the "jira.issue" variable.
4. A table get the issue sub-tasks.

![2020-01-03_09h28_06.png](https://community.atlassian.com/t5/image/serverpage/image-id/77670i31E0B6FEC2A34308/image-size/large?v=v2&px=999 "2020-01-03_09h28_06.png")![2020-01-03_09h29_04.png](https://community.atlassian.com/t5/image/serverpage/image-id/77671i43AEC97F17B282CF/image-size/large?v=v2&px=999 "2020-01-03_09h29_04.png")![2020-01-03_09h30_24.png](https://community.atlassian.com/t5/image/serverpage/image-id/77669i04ED52EBB18D44A0/image-size/large?v=v2&px=999 "2020-01-03_09h30_24.png")![2020-01-03_09h30_41.png](https://community.atlassian.com/t5/image/serverpage/image-id/77672i2084EA9C8FAA1289/image-size/large?v=v2&px=999 "2020-01-03_09h30_41.png")


author: Shannon S
body: Hello Guillaume,

Thank you for explaining your requirements.

Since you are using Confluence Server, you could do this with [a user macro](https://confluence.atlassian.com/doc/writing-user-macros-4485.html).

There are a few threads below where users had similar requirements and they created a user macro for this:

* [Solved: How do you add template variables as macro parameters or in plain text macro bodies?](https://community.atlassian.com/t5/Confluence-questions/How-do-you-add-template-variables-as-macro-parameters-or-in/qaq-p/116958)
* [Solved: Using template variables as input parameters to jira gadget](https://community.atlassian.com/t5/Confluence-questions/Using-template-variables-as-input-parameters-to-jira-gadget/qaq-p/189292)

Have a look there, as it may be able to help you with your requirements.

Regards,

Shannon


author: Patricia Mayer
body: Hi, I'm trying to do something very similar, however we use Confluence Cloud version, can this be done please?


Tags: atl-adm

confluence-server