How to generate a tip or warning report in a confluence page?
Asked by ABoerio:

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


Answers:
author: ABoerio
body: Hi all,

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

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

which look like this in page

![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/191931iAFB71BA3F2C79EC0/image-dimensions/300x92?v=v2 "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](https://community.atlassian.com/t5/image/serverpage/image-id/191929i5AD8D135259B7713/image-size/large?v=v2&px=999 "image.png")

It's rough, but does what I need.

Ciao, Andrea


Tags: confluence-server

report

scriptrunner

server

user-macro