Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Confluence User Macro - Execute search query

Michael Ruderer July 7, 2017

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
Answer accepted
Stephen Deutsch
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 7, 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).

Michael Ruderer July 10, 2017

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
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 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>

 

Michael Ruderer July 10, 2017

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
TAGS
AUG Leaders

Atlassian Community Events