Forums

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

Scriptrunner script to edit hyperlinks

Gaven Ray
Contributor
January 16, 2025

I have a script to edit the text on a page 

 


import com.atlassian.confluence.pages.PageManager import com.atlassian.confluence.spaces.SpaceManager import com.atlassian.sal.api.component.ComponentLocator import com.atlassian.confluence.core.DefaultSaveContext def oldText = '' def newText = '' def targetSpaceId = '' def spaceManager = ComponentLocator.getComponent(SpaceManager) def pageManager = ComponentLocator.getComponent(PageManager) def targetSpace = spaceManager.getSpace(targetSpaceId) def spacePages = pageManager.getPages(targetSpace, true) spacePages.each{page -> def pageBody = page.getBodyAsString() if (pageBody.contains(oldText)){ pageBody = pageBody.replace(oldText, newText) page.setBodyAsString(pageBody) pageManager.saveContentEntity(page, DefaultSaveContext.DEFAULT) log.info("Text replaced in page by Scriptrunner '${page.title}' in space '${targetSpace.name}'") } }

 I would like it to be able to change the background link to a hyperlink on a Confluence page. 

1 answer

1 accepted

6 votes
Answer accepted
Benjamin
Community Champion
January 16, 2025

HI @Gaven Ray ,

 

Found an article that may help you with the problem you are trying to solve by adding html tags in your script.

 

https://community.atlassian.com/t5/Marketplace-Apps-Integrations/Hyperlink-with-scriptrunner/qaq-p/880786

 

Hope this helps.

Gaven Ray
Contributor
January 16, 2025

Thanks I will see if I can make this work with what you sent.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
AUG Leaders

Atlassian Community Events