Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Writing a user macro similar to Task report Macro

t0mhAn3110 October 14, 2021

Hi people,

I am quite new to writing User Macros in Confluence.

I want to write a user macro with almost the same functionality as the standard 'Task report' macro with the only difference that only the page should be pre-defined to the current page if the Space(s) and Page(s) is left blank. 

Curious to know if anybody had already tried writing and replicating the Task Report macro?

Any support would be gladly appreciated.

Thanks in advance

1 answer

1 vote
Dominic Lagger
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.
October 14, 2021

Hi @t0mhAn3110 

This should be very easy.

Every confluence page has it's own "storage format". There you find xml-based code unrendred.

So the task report will shown as followed:


<p><ac:structured-macro ac:name="tasks-report-macro" ac:schema-version="1" ac:macro-id="32f7ec75-450b-4db7-beb2-f5516e5a0ae9"><ac:parameter ac:name="pages">146866177</ac:parameter></ac:structured-macro></p>

There you just have to replace the pages parameter with the actual pageid.

Full macro here:

## Macro title: My Macro
## Macro has a body: Y or N
## Body processing: Selected body processing option
## Output: Selected output option
##
## Developed by: My Name
## Date created: dd/mm/yyyy
## Installed by: My Name

## This is an example macro
## @noparams


<p><ac:structured-macro ac:name="tasks-report-macro" ac:schema-version="1" ac:macro-id="32f7ec75-450b-4db7-beb2-f5516e5a0ae9"><ac:parameter ac:name="pages">$content.getId()</ac:parameter></ac:structured-macro></p>

 

Hope this helps.

Regards, Dominic

Bill Bailey
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.
October 15, 2021

I think the poster is looking to not just wrap an instance of the macro, but make java calls to retrieve the data and reformat as needed.

t0mhAn3110 October 18, 2021

Hi @Dominic Lagger ,

Thank you for the response :)

I tried this:

## Developed by: 
## Date created:
## @param space:title=Space|type=spacekey
## @param user:title=Username|type=username|desc=Select username to display
## @param page:title=Page|type=confluence-content|required=true|desc=Select a page to use

#set( $spaceKey = $paramspace)
#set ( $pageId= $content.id)
#set ( $pageId= $pageManager.getPage($spaceKey ,$parampage).getContentId().toLong() )
#set ( $pageTitle= $pageManager.getPage($spaceKey ,$parampage)
#set ($userKey = $userAccessor.getUserByName($paramuser).getKey())
<ac:structured-macro ac:name="tasks-report-macro" ac:schema-version="1" ac:macro-id="32f7ec75-450b-4db7-beb2-f5516e5a0ae9">
<ac:parameter ac:name="pages">$pageId</ac:parameter>
</ac:structured-macro>

But unfortunately does not seem to work.  

Moreover, I am also trying that if the Space(s) and Page(s) is left blank, the page should be pre-defined to the current page.

Dominic Lagger
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.
October 18, 2021

Why do you use all these variables like "userKey, pageTitle", and so on?

instead of "$pageid" use the

$content.getId()

 as I did.

t0mhAn3110 October 19, 2021

Becuase I need these params.

Anyways, is there anyway to pre-defined to the current page if the Space(s) and Page(s) is left blank?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events