Confluence User Macro - Execute search query

Hello everybody,

is it possible to perform a search query in the background within a confluence user macro?

I want to display the found results in a bullet list at the confluence page. I have found some classes within the confluence SDK but i dont know how to get them working within velocity.

Example classe which could perform a search:

Have you got any ideas?

Thanks in advance!

Michael

1 answer

1 accepted

3 votes
Stephen Deutsch Community Champion Jul 07, 2017

Instead of trying to mess with all that, why not just piggyback on top of one of the existing macros?

This should work for generating a CQL query:

## @noparams
$action.getHelper().renderConfluenceMacro('{contentbylabel:showLabels=false|showSpace=false|cql=type = "page" and <rest of cql>}')

This displays more or less a bulleted list (with a page icon instead of bullets. If you want to modify the results, just assign the results to a variable and directly modify the text with the text manipulation methods available to velocity (for example, to not show anything when there are no results instead of the no labels found panel).

Hello Stephen,

thanks for your reply!

That´s a great idea and is working fine.

One problem: I am searching for a name which can be found within an attachment. Content By Label is returning then something like this:

"Page Link" > "Link to attachment"

I have tried with string functions to just return the "Page Link" but this is not working fine. I have tried .split() and substring in combination with indexOf without any success. With the .split() function i only get returned an address of the string object:

2017-07-10 09_18_47-Link auf OrgChart Test - Michael Ruderer - ONE - confluence.png

This is normally an array and i don´t know how to get the value within velocitiy not the object address...

Have you got any ideas?

Best Regards,

Michael

Stephen Deutsch Community Champion Jul 10, 2017

Hi Michael,

Actually, what you get returned is a list of strings. Unfortunately velocity (at least the version that is included in Confluence) doesn't have very good list functions, so you're pretty much limited to #foreach ($listItem in $list). Here is something fairly simple that should work:

 

## @noparams
#set ( $htmlString = $action.getHelper().renderConfluenceMacro('{contentbylabel:showLabels=false|showSpace=false|cql=type = "attachment"}') )
<ul>
#foreach ( $htmlTag in $htmlString.split(' <') )
  #set ( $htmlTag = '<' + $htmlTag )
  #if ( $htmlTag.contains('/download/attachments/') )
    <li>$htmlTag</li>
#end #end </ul>

 

Hi Stephen,

thanks that´s exactly what i needed!

Thank you very much!

Best Regards,

Michael

 

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Kesha Thillainayagam
Posted Apr 13, 2018 in Confluence

We want to hear how your non-technical teams are using Confluence!

Hi Community! Kesha (kay-sha) from the Confluence marketing team here! Can you share stories with us on how your non-technical (think Marketing, Sales, HR, legal, etc.) teams are using Confluen...

374 views 20 10
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you