Skip to end of metadata
Go to start of metadata

What does it do?

What are the pre-requisites?

You will need to have VisualScript and ScriptRunner Apps installed on your instance of Confluence

How do I get started?

High Level Steps

  1. Ensure you have installed VisualScript for Confluence and ScriptRunner for Confluence
  2. Create a ScriptRunner REST Endpoint
  3. Copy the REST Endpoint URL you are trying to use
  4. Add a Visual Script Macro
  5. Paste the REST Endpoint URL as the Macro parameter
  6. Save the Page

Detailed Steps

Step 1:

  • Navigate to the Add-ons administration page using the cog in the top right corner
  • Find the ScriptRunner section in the left-hand panel and select REST Endpoints
  • Click the Add New Item button and select Custom endpoint
  • Choose from the 2 examples at the bottom of this document, expand the example, copy and paste the code into the in-line script
  • Click Add


Step 2:

  • In the list of REST Endpoints, find your newly added endpoint. This will show up as the name of the method of the endpoint. For example if you chose the Org chart example then it will be called getOrgChart
  • Right click on the hyperlink of your endpoint and select Copy Link Address
  • Using the Space dropdown in the banner menu Navigate back to the page where you want your Visual Script to be added

Step 3:

  • Click the Edit button in the top right of the page

  • Click + dropdown in the page edit banner menu at the top of the page

  • Search for the VisualScript macro and add it

  • Paste the url that you copied of your endpoint into the alert input that pops up and click OK.  If you have chosen an example that requires a parameter then add your parameter to the url
  • It may ask you to enter the height of the macro.If so, enter the height you wish it to be and click OK. 
  • Click Update in the bottom right of the page



Step 4: Example end result


Examples

Example 1:

This is an example REST endpoint for an Org Chart. Example URL - https://<YOURBASEURL>/rest/scriptrunner/latest/custom/getFlowChart?startingLabel=hello

Org Chart Example
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.json.JsonSlurper
import groovy.transform.BaseScript
import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response
@BaseScript CustomEndpointDelegate delegate
 
getOrgChart(httpMethod: "GET"){ MultivaluedMap queryParams ->
 
    return Response.ok(getOrgChartSdon()).build()
}
 
static String getOrgChartSdon() {
    def slurper = /
{
    "DiagramType":"Orgchart",
    "RootShape":[{
        "Label":"Top Dog",
        "ShapeList":
        [{
            "Direction":"Right",
            "Shapes":     [
                   {"Label":"Ivanka"},
                   {"Label":"Jared"},
                   {"Label":"Donald Jr","ShapeList":[{"Shapes":[{"Label":"Donald III"}]}]},
                   {"Label":"Melania"},
                   {"Label":"Baron","ShapeList":[{"Shapes":[{"Label":"Flopsy"},{"Label":"Mopsy"}]}]
                   }]
        }]
        }]
    }
/
}


Example 2:

This is an example REST endpoint for an Flow Chart. This example takes in a parameter named 'startingLabel', you will need to supply this in the url when adding it to the gadget. For example https://<YOURBASEURL>/rest/scriptrunner/latest/custom/getFlowChart?startingLabel=hello

Flow Chart Example
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.json.JsonOutput
import groovy.json.JsonSlurper
import groovy.transform.BaseScript
 
import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response
@BaseScript CustomEndpointDelegate delegate
 
getFlowChart(httpMethod: "GET"){ MultivaluedMap queryParams ->
 
    def startingLabel = queryParams.get("startingLabel")?.first()
    return Response.ok(getFlowChartSdon(startingLabel)).build()
}
 
static String getFlowChartSdon(def startingLabel) {
    def slurper = /
{
  "DiagramType": "Flowchart",
  "RootShape": [
    {
      "ID": "1",
      "Label": "${startingLabel}",
      "ShapeList": [
        {
          "Shapes": [
            {
              "ID": "2",
              "Label": "Step 1"
            },
            {
              "ID": "3",
              "Label": "Step 2"
            },
            {
              "ID": "4",
              "Label": "Step 3",
              "ShapeList": [
                {
                  "Direction": "Down",
                  "Shapes": [
                    {
                      "ID": "5",
                      "Label": "Decision A"
                    }
                  ]
                }
              ]
            },
            {
              "ID": "6",
              "Label": "Step 4"
            },
            {
              "ID": "7",
              "Label": "Step 5"
            }
          ]
        }
      ]
    }
  ],
  "Returns": [
    {
      "StartID": "5",
      "EndID": "3"
    },
    {
      "StartID": "7",
      "EndId": "2"
    }
  ]
}
/
}
  • No labels