The Adaptavist Group LogoDocumentation

Creating a Page When a Form is Submitted

Creating a new page from a form submission is useful if form responses require a follow-up or collaborative action, for example, if a user submits an internal feature request or events proposal.

Creating a new page from a form submission is useful if form responses require a follow-up or collaborative action, for example, if a user submits an internal feature request or events proposal. If you have Script Runner for Confluence installed, you can run a script on the "FormSubmitEvent" that creates a new Confluence page when a form is submitted.

Instructions

  1. Create a new Form that includes input fields to collect a specified Space Key, Page Title and .
    Note: You can include additional fields such as a parent page or Forms Attachment macro if needed.

  2. Configure the Event Listener for FormsSubmitEvent, where the spaceKey, pageTitle, and pageContent correspond to the name parameter defined for the macros in your form. When the form is submitted, a new page is created with the values entered by the user.

    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)
    }

Search documentation

Start typing to search the docs.