Skip to end of metadata
Go to start of metadata

If you have Script Runner for Confluence installed you can run a script on the "FormSubmitEvent". 

Firstly,  create a new page in the specified space, with the indicated title and page content.

 Next,  add a custom event handler,  using the "FormSubmitEvent"   


and the inline script code: 

import com.atlassian.confluence.core.DefaultSaveContext
import com.atlassian.confluence.pages.Page
import com.atlassian.confluence.pages.PageManager
import com.atlassian.confluence.spaces.SpaceManager
import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.xwork.FileUploadUtils
import groovy.json.JsonSlurper

try {
    String event = ((HashMap<String, String>) binding.variables).get("event").structuredValue
    Map<String, String> data = new JsonSlurper().parseText(event)

    List<FileUploadUtils.UploadedFile> uploadedFiles = ((HashMap<String, String>) binding.variables).get("event").uploadedFiles

    def pageManager = ComponentLocator.getComponent(PageManager)
    def spaceManager = ComponentLocator.getComponent(SpaceManager)

    def spaceKey = data.get("spaceKey")[0]
    def pageTitle = data.get("pageTitle")[0]
    def pageContent = data.get("pageContent")[0]

    def targetPage = new Page(
        space: spaceManager.getSpace(spaceKey),
        title: pageTitle,
        bodyAsString: pageContent,

    pageManager.saveContentEntity(targetPage, DefaultSaveContext.DEFAULT)

} catch (anyException) {
    log.warn("Failed to create page for new user", anyException)

now when the form above submitted, a new page is created. 

  • No labels