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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.