Use confluence page properties in "Jira Issue/Filter" macro
Asked by Andreas Eder:

Hi,

is there a possibility to use Page properties as filter criteria in "Jira Issue/Filter" macro?

I have some confluence-pages where some information from jira issues is displayed using some Jira Issue/Filter-macros.

I'd like to define some filter criteria once in the page, all jira-filter should use this attribute.

e.g:

* all jira-filter should use a defined timestamp / date to display all items resolved before this date.


Answers:
author: Roma Bubyakin
body: Hello [@Andreas Eder](/t5/user/viewprofilepage/user-id/3029414),

It seems that you have a quite special request  
I can propose for it our app [User Macro for Confluence Cloud](https://marketplace.atlassian.com/apps/1232013/user-macro-for-confluence-cloud?hosting=cloud)

If I understand you correctly, you have a page. The page has page property. The page property should be used in JQL for searching (and representing) issues from Jira.

Here is how I did it with our app.

Our Jira and JQL with the word *"site"* :  
![Jira_JQL_search.png](https://community.atlassian.com/t5/image/serverpage/image-id/341862iB798D1458A539533/image-dimensions/486x222?v=v2 "Jira_JQL_search.png")

I have added to the target page property "filter" with the value *"site"*

![Confluence_page_properties.png](https://community.atlassian.com/t5/image/serverpage/image-id/341863i6156C9A90AEBF937/image-dimensions/511x166?v=v2 "Confluence_page_properties.png")

And now the most interesting, I have created a new User Macro which

1. gets *"site"* from the page properties
2. make the search in Jira
3. and represent tickets as a table

```
## the key of the property we are looking for
#set($propertyKey = "filter")

## get all properties for the current page
#set($properties = $ConfluenceManager.get("/wiki/api/v2/pages/${page.id}/properties").results)
## looking for our property one-by-one
#foreach ( $property in $properties )
  ## check if current property same as $propertyKey
  #if ($property.key == $propertyKey)
    ## store the value int $filter variable
    #set($filter = $property.value)
  #end
#end

## setup JQL with the $filter value
#set($jql = "text ~ '${filter}' AND project = TEST ORDER BY created DESC")

## making Jira search
#set($issues = $JiraManager.get("/rest/api/3/search?jql=${jql}").issues)

## show results as a simple table
#set( $jiraUrl = $StringUtils.remove($baseUrl, "wiki/") )
<table class="aui aui-table-sortable">
  <thead>
    <tr>
      <th class="aui-table-column-issue-key">Issue key</th>
      <th>Summary</th>
      <th>Status</th>
    <tr>
  </thead>
  <tbody>

#foreach ( $issue in $issues )
  <tr>
    <td><a href="${jiraUrl}/browse/${issue.key}">$issue.key</a></td>
    <td>$issue.fields.summary</td>
    <td>$issue.fields.status.name</td>
  </tr>
#end

  </tbody>
</table>
```

On the app code looks much better

![Jira_Issue-Filter.png](https://community.atlassian.com/t5/image/serverpage/image-id/341864i22AFD617499D1152/image-dimensions/468x390?v=v2 "Jira_Issue-Filter.png")

And the final result: **list of issues listed on the page**

![Final_result.png](https://community.atlassian.com/t5/image/serverpage/image-id/341865i7284D6017A4AADAD/image-size/large?v=v2&px=999 "Final_result.png")

I hope, I understand you correctly and this is what you need.  
User Macro app provides a lot of possibilities for custom logic, integration, and representation.

Regards,  
Roman, CEO of Wombats Corp

comments: author: Andreas Eder
body: Hello Roman,

It's nearly a possible solution, we use confluence data center.

I'll search for possible macro-apps.

I hoped there is an other way to re-use jira-filters in confluence pages :)

We use confluence to report data periodically, this pages contains many jira-filters. The only difference are some filter criteria. (e.g. resolved-time, fix-version). Currently, I have to adapt any filter manually - on the one hand, this requires a certain amount of effort, on the other hand, there is a risk of error.

Regards,

Andreas


author: Roma Bubyakin
body: On DC you have User Macro out-of-the-box and can create that thing from the admin page


author: Andreas Eder
body: Thank you,

As far as I understood, I need a macro for each Jira-Filter.

I'll give this a try and test macros.


author: Roma Bubyakin
body: You can write one macro and then parametrize it via User Parameters

So on adding the macro, the user specifies a parameter (JQL or/and property-key)

One macro will fetch different data based on the User Parameter, however, display it with the same logic

I'm pretty sure that you can achieve it within DC User Macro.  
In any case, you can reuse my code partially (it has \~80% compatibility).  
The main pitfall is finding a way to fetch data from Jira into Confluence via macro...

Regards, Roman


Tags: confluence-data-center

data-center

filter

macro