Skip to end of metadata
Go to start of metadata

As a support manager, I want to allow users the ability to submit a form using Forms for Confluence which will be sent to ScriptRunner on a JIRA instance. Once received, ScriptRunner creates a new issue with the information submitted. The form submission must also be recorded locally in Confluence in the internal database. 


This scenario describes the situation where a submitted form can be handled in the usual way and then submitted to ScripRunner for Jira where some processing can be done on the submitted form and an issue created.

Please note the following instructions are for demonstration. Each Confluence and Jira instance can have their own security policies and custom configurations that should be taken into consideration. This is just a small demonstration of what steps would be required to get basic functionality working. The powerful combination of ScriptRunner for Jira and Forms for Confluence is capable of much more.

Instructions

Setting up the application link between Confluence and Jira

In this step we set up an application link that will link Confluence and Jira.

  1. In Confluence, navigate to Confluence Administration > General Configuration > Application Links. The location of Application Links in Jira depends on the version of Jira.
  2. Enter the URL of the relevant Jira instance and click Create New Link.



  3. You might be required to validate your credentials at this point.
  4. Tick the relevant boxes and continue. If you are an administrator on both instances make sure you select the checkbox. This can save some time as the remote application link will automatically be created on the Jira instance (username and password should be the same on both instances).



  5. You should see a message asking you to wait whilst being redirected to the Jira instance.
  6. You will once again be presented with a window to validate your credentials, but this time it is for Jira.
  7. The next window will display some information about the link that will be created in Jira (similar to the one above). Once continue is clicked, the link will be created in Jira and you will be redirected back to Confluence.
  8. A success message should be displayed, and the application link will appear.

  1. Click edit on the application link in the Application Links section.
  2. Both outgoing and incoming authentication need to be set up. For the purpose of this demo we will be using 2-Legged OAuth. If there are problems with setting up the authentication such as the page not loading properly, try logging out and back in to Jira/Confluence.




  3. Do the same authentication configuration for the application link in Jira and Confluence.

Setting up the ScriptRunner REST endpoint in Jira

  1. More information about ScriptRunner REST endpoints can be found here.
  2. Navigate to Add-ons > ScriptRunner > REST Endpoints.
  3. Click custom endpoint and add some code that will process the form that will be submitted from Confluence.
  4. Our custom endpoint is below with imports omitted. It captures the submitted form which contain the following fields: project, summary and description. The issue is then created and a message sent back to Confluence which the user who submitted the form will see as an info message.

    import com.atlassian.jira.component.ComponentAccessor
    import com.atlassian.jira.issue.IssueInputParametersImpl
    import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
    import groovy.json.JsonSlurper
    import groovy.transform.BaseScript
    
    import javax.ws.rs.core.MediaType
    import javax.ws.rs.core.MultivaluedMap
    import javax.ws.rs.core.Response
    
    @BaseScript CustomEndpointDelegate delegate
    
    receiveFromForms(httpMethod: "POST", groups: ["jira-administrators"]) { MultivaluedMap queryParams, String body ->
    
       def params = new IssueInputParametersImpl()
       def issueService = ComponentAccessor.getIssueService()
       def constantsManager = ComponentAccessor.getConstantsManager()
       def forms = new JsonSlurper().parseText(body) as Map<String,String>
    
       def projectManager = ComponentAccessor.getProjectManager()
       def project = projectManager.getProjectObjByKey(forms.project)
    
       // Get a user who has permissions to create issues
       // This must be changed to an existing user on your instance
       def user = ComponentAccessor.getUserManager().getUserByKey("admin")
       params.setProjectId(project.id)
       // Defines the Type of Ticket to create. Please note all Jira types doesn't support all issue types, that is you can not create a "Bug" in Jira Core.
       params.setIssueTypeId(constantsManager.allIssueTypeObjects.findByName("Task").id)
       params.setReporterId(user.name)
       params.setSummary(forms.summary)
       params.setDescription(forms.description)
    
       def createValidationResult = issueService.validateCreate(user, params)
       assert  !createValidationResult.errorCollection.hasAnyErrors()
    
       def issue = issueService.create(user, createValidationResult).issue
       log.debug "Created issue : ${issue.key}"
    
       return Response.ok("Thanks for creating an issue").type(MediaType.TEXT_HTML).build()
    }



  5. Note that in this case if the form submitted does not contain these exact fields, an error will be shown to the user who submitted the form.

Setting up a ScriptRunner Form Id in Confluence

  1. Navigate to Confluence Administration > General configuration > Forms for Confluence.
  2. Click add a new form configuration.



  3. Set up a new Form Id using ScriptRunner as the destination.
  4. Set up another unique Form Id with destination type set as internal database. This one will be use to store the submitted form on Confluences internal database.


Setting up a Form in Confluence

  1. Create a new page.
  2. Add a Form to a page.
  3. Edit the Forms macro and enter the two Form IDs created in the previous step.

     

  4. Create the input fields in the Form that the ScriptRunner REST endpoint is expecting to receive, in this case it is project, summary and description. They are case sensitive.




  5. Populate the fields with some values. In this case the project input field value must match an actual project key in JIRA. In this example our project in JIRA is an Agile project. Other types of projects might not work with the REST enpoint in this example.
  6. On first submission you might be required to authenticate.



  7. Follow the link and click allow.
  8. Submit the Form again.
  9. If all went well the user should receive a message back from the JIRA instance. In this case we show a message containing a link to the JIRA issue created.


  10. Note that all responses from ScriptRunner as above in the info message, will be saved in the internal database for Confluence through the associated Form Id. This can be accessed by navigating to Confluence Administration > General configuration > Forms for Confluence > ScriptRunner Responses.






  • No labels