How to create an additional jira-page with scriptrunner

Axel Joester July 11, 2019

It is possible to enhance existing jira pages with scriptrunner, but I can'T figure out, how to create a new page. Is this at all possible?

Current example: I wrote a script to display the configuration of all my jira servicedesk queues. I use it for QA, because I wan't to check, if all queues display the same fields in the same order. Works well.

I can of course run the script in adaptavist script console. It formats its output as html, which is then displayed when I press the run button. 

But I'd like to run the script on clicking a menu item and have it display the result in it's own page. Or link it as a new page in the admin pages. Or, if not possible otherwise, package it in a gadget and use it on a dashboard.

There seem's to be no way to do any of this. I would not want to create a extra-pane in an issue-view. 

Any idea, anyone?

4 comments

Comment

Log in or Sign up to comment
Daniel Garcia October 21, 2019

I'd love to know as well  @Nic Brough -Adaptavist- 

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 22, 2019

I can't think of a way to do this without writing an app that would inject a new page into Jira.  

You could get the content for such a page from ScriptRunnner, I'm sure, and I've written gadgets that draw 99% of their content from a ScriptRunner REST endpoint, so I know that works.  But I don't know a way SR could create an entire new page on its own.

Axel Joester October 22, 2019

Maybe SR could make this a new feature?

A new option in "create script fragment":

Custom page

Parameters: 

  • relativ url the page shall be reached by
  • script to call to render page content
Daniel Garcia October 23, 2019

Depending on where in the navigation hierarchy lives, the page would need a different template.

When I need to do something like this I just create a dialog box and make it really big. Not ideal but it works.

Would be a cool feature though.

Daniel Garcia February 16, 2020

OK, I've figured this out.

Firstly with REST endpoint we can create a simple HTML page

import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.transform.BaseScript
import javax.servlet.http.HttpServletRequest
import javax.ws.rs.core.MediaType
import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response

@BaseScript CustomEndpointDelegate delegate

testPage() { MultivaluedMap queryParams, body, HttpServletRequest request ->
Response.ok().type(MediaType.TEXT_HTML).entity("""<html>
<head>
<title>Hello World</title>
</head>
<body id="jira" class="aui-layout aui-theme-default">
<h1>Hello world</h1>
</body>
</html>
""").build()
}

The downside to this approach is

  • You can't use velocity or Soy templates
  • You can't add resources

I'm still working on templates but adding resources is easy (when you know how)

import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.transform.BaseScript
import com.atlassian.jira.component.ComponentAccessor
import javax.servlet.http.HttpServletRequest
import com.atlassian.webresource.api.UrlMode
import com.atlassian.webresource.api.assembler.PageBuilderService
import com.atlassian.webresource.api.assembler.WebResourceAssembler
import javax.ws.rs.core.MediaType
import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response

@BaseScript CustomEndpointDelegate delegate

testPage() { MultivaluedMap queryParams, body, HttpServletRequest request ->
PageBuilderService pageBuilderService = ComponentAccessor.getComponentOfType(PageBuilderService)
WebResourceAssembler assembler = pageBuilderService.assembler()
List<String> requiredResources = ["jira.webresources:jquery","jira.webresources:global-static"]
requiredResources.each{String moduleKey ->
assembler.resources().requireWebResource(moduleKey)
}

Writer sw = new StringWriter()
sw << """<html>
<head>
<title>Hello World</title>
"""
pageBuilderService.assembler().assembled().drainIncludedResources().writeHtmlTags(sw, UrlMode.AUTO)
sw << """</head>
<body id="jira" class="aui-layout aui-theme-default">
<h1>Hello world</h1>
</body>
</html>
"""

Response.ok().type(MediaType.TEXT_HTML).entity(sw.toString()).build()
}
Axel Joester April 23, 2020

Sorry for answering late, I didn't figure out, that your script really solves my problem:

Yes, that's it! Brilliant! Thank you!

Of course, I'd love to see the normal Jira-menus above my page, but I'll just activate the text gadget, so I can use it on a dedicated dashboard to display my new page in it via an iframe.

It's far from perfect, but it does meet my requirements. Our Jira is strictly internal, so the security implications of activating the text gadget are a lesser concern.

Like Matt Doar likes this
Rodolfo So June 22, 2022

Hi @Daniel Garcia,

 

Can you provide sample screenshot for this rest endpoint result?

 

Thank you!

TAGS
AUG Leaders

Atlassian Community Events