Forums

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

How to generate a tip or warning report in a confluence page?

ABoerio
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.
March 18, 2022 edited

Hello, 

I know and make use of the task report in Confluence. Extremely useful.

What I'd like to do is to generate the same kind of report, creating a dedicated macro that a user could place in a page, regarding warnings, tips, etc .... that might have been placed in some pages of one or more spaces.

I actually imagine the same kind of search criteria of the task report (by label, by space, etc... "search for all the warning boxes placed in the pages labelled as ... in that space, and show me the body of this macro, the page where it's placed and so on").

I'd like to generate then a user macro called "decision", which can be used by a user to embed a paragraph in, and so classify this paragraph as a decision. It's not difficult to generate this "decision" macro, while I have more difficult (for me) to create the report to generate the summary list.

If there's an easy way to make use of the already existing warnings and tips macros, and summarize them somehow in a page, I could start from it.

I can naturally study dedicated scriptrunner scripts, but if possible I'd like to make use of macros.

 

Any hints?

Thnks in advance.

CIao, Andrea

1 answer

0 votes
ABoerio
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.
April 7, 2022

Hi all, 

As I haven't found any alternative, I've created our own decisionmark macro.

image.png

which look like this in page

image.png

Then, by Script, I'll search for the macro usage and collect the relevant information.

 

import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.confluence.pages.Page
import com.atlassian.confluence.pages.PageManager
import com.atlassian.confluence.spaces.Space
import com.atlassian.confluence.spaces.SpaceManager
import com.atlassian.confluence.pages.Attachment
import com.atlassian.confluence.pages.AttachmentManager
import com.atlassian.confluence.core.DefaultSaveContext
import groovy.xml.MarkupBuilder
import java.math.RoundingMode
import org.jsoup.Jsoup

def spaceManager = ComponentLocator.getComponent(SpaceManager)
def pageManager = ComponentLocator.getComponent(PageManager)
def attachmentManager = ComponentLocator.getComponent(AttachmentManager)
def writer = new StringWriter()
def xml = new MarkupBuilder(writer)


//def spacesToCheck=['~BOERIO']
//def spacesChecked=spaceManager.allSpaces.findAll{it-> spacesToCheck.contains(it.key)}
def spacesChecked=spaceManager.allSpaces.findAll{it instanceof Space}

spacesChecked.each(){
spaceChecked->
def pagesChecked=pageManager.getPages(spaceChecked, true).findAll{it instanceof Page}
//def pagesChecked=pageManager.getPages(spaceChecked, true).findAll{it.title == 'Check decision'}
pagesChecked.each(){
pageChecked->
//Get content page for parsing
def body = pageChecked.bodyContent.body
def parsedBody = Jsoup.parse(body)
def decisions = parsedBody.select("ac|structured-macro").findAll{it.attr('ac:name')=="decisionmark"}
//log.warn(parsedBody)
//log.warn(decisions)
decisions.each(){
decision->
def decisionRef=decision.select("ac|rich-text-body").text()
log.warn("Space: ${spaceChecked.name} - Page: ${pageChecked.title} - Decision: ${decisionRef}")
}

}
}

At the moment I'm writing just in log, then I'll write a table in a Confluence page (that's the reason for all the other unused libraries already imported).

image.png

It's rough, but does what I need.

Ciao, Andrea

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events