Forums

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

Append Content to page with Scriptrunner: size limits with getBodyAsString() & setBodyAsString()?

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 Champions.
May 6, 2019

Hi, 

I've managed to append content to an existing page in Confluence by scriptrunner console.

Below a sample of the code I'm using, which I know it's far from being an elegant programming example, :-), but in the end it works, and I'm using to introduce text, tables, etc...

//Libraries
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.sal.api.component.ComponentLocator
import com.atlassian.confluence.core.DefaultSaveContext

//Defining the management objects
def spaceManager = ComponentLocator.getComponent(SpaceManager)
def pageManager = ComponentLocator.getComponent(PageManager)
def attachmentManager = ComponentLocator.getComponent(AttachmentManager)

//Defining the page to update (the page already exists)
def outputPage=pageManager.getPage("~BOERIO", "Output")
//Get the current content of the page
def contentEntityObject = outputPage.getContentEntityObject()
def pageBody=outputPage.getBodyAsString()

// I want to add this text to the page
String appendedText="<p>Hello Confluence Page!</p>"

//Building the string with the new content
String outputPageBody=pageBody+appendedText

//Assigning the new content to the page
contentEntityObject.setBodyAsString(outputPageBody)

//Saving the page
pageManager.saveContentEntity(outputPage, DefaultSaveContext.DEFAULT)

//return outputPageBody

My question is related to the risk to reach a size limit for the string I'm building and assigning as new page content. Will I reach the point where the current page content is no more manageable with a string?

Is there a better approach to follow?

Thanks in advance for any suggestion.

Ciao, Andrea

 

1 answer

Suggest an answer

Log in or Sign up to answer
0 votes
Ste Wright
Community Champion
May 7, 2022

Hi @Mouna Hammoudi 

Not that I know of - the field types available are: Text, Number, Date, Datetime

You could check with Adaptavist Support though - see contact options on their Marketplace App listing's Support tab

Let us know what Support say if you contact them!

Ste

TAGS
AUG Leaders

Atlassian Community Events