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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,559,276
Community Members
 
Community Events
184
Community Groups

delete macro reference with Scriprunner

Michael Regelin
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.
Oct 23, 2018

Hello,

I need to delete all references to a macro (in this case: tracking-info) on all pages.

Is it possible with scriptrunner to run this job that would be based on a cql and delete all occurences of the macro ?

No need to keep the content inside the body of macro. Of course, it would be appreciate ;-)

 

Thanks for your help.

 

Michael

1 answer

1 accepted

1 vote
Answer accepted
Jonny Carter
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.
Oct 15, 2020

Yup! This is definitely possible with ScriptRunner.

You could setup a CQL Escalation Service job (or just use the "Run Now" to run it as a one-off). A query like

macro = tracking-info and type = page 

should find all pages with the tracking-info macro in them.

As to doing the update, I've got an example up at of bulk-updating a table, but this should be just as possible to remove macro content.

I'm not 100% sure what the tracking-macro's storage format looks like, but many macros are wrapped in an ac:structured-macro tag with an ac:name attribute. You can find those elements in the Confluence storage format with a little massaging for the name-spaced format.Something like this in the inline script blank of a CQL Esclatation Service job should remove the macro and its contents entirely.

import com.atlassian.confluence.pages.PageManager
import com.atlassian.sal.api.component.ComponentLocator
import org.jsoup.Jsoup

def pageManager = ComponentLocator.getComponent(PageManager)
hits.each { page ->
def body = page.bodyContent.body
def parsedBody = Jsoup.parse(body)
def macroBody = parsedBody.select('ac|structured-macro').attr('ac:name', 'tracking-info')
if (!macroBody.empty) {
pageManager.saveNewVersion(page) { pageObject ->
macroBody.remove()
pageObject.setBodyAsString(parsedBody.toString())
}
}
}

Saving the macro's body should be possible, but is left as an exercise to the reader. :)

Also, we've got some work in the backlog to bulk update macros with less code: https://productsupport.adaptavist.com/browse/SRCONF-1238

Michael Regelin
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.
Oct 16, 2020

Thanks Jonny for your script.

 

I tested it as is but it doesnt work. I have a script error when pasting it in the script inline windows. I understand the idea. So I will try to make it work.

Thanks again.,

 

Michael

Jonny Carter
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.
Oct 16, 2020

Best of luck, Michael. One pitfall might be that this won't work via the script console -- I'm assuming you're putting it into the code blank for a CQL Escalation Service Job.

Another possible pitfall is that the storage format for the tracking-info macro looks different than my script assumes. You can read up more on that format at https://confluence.atlassian.com/doc/confluence-storage-format-790796544.html

If you post some sample storage format, I may be able to give you some pointers on parsing it via JSOUP.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events