- Configuration
- Introduction
- List theme
- Cards theme
- Request Details View
- Requests View
- Login screens
- Categorization
- Portal descriptions
- Design inspirations
- Cards design inspirations
- List design inspirations
ScriptRunner compatibility
Learn how ScriptRunner app is compatible with Theme Extension
Theme Extension for Jira Service Management provides its web resource context to enable integration with external apps, such as ScriptRunner.
The web resource context is theme-extension-view-portal
.
This allows you to further customize both your Jira and Theme Extension for Jira Service Management with external apps and scripts.
To integrate Theme Extension for Jira Service Management with ScriptRunner, you need to:
- define a REST endpoint in ScriptRunner. For more information, see Scriptrunner documentation.
- define
theme-extension-view-portal
as web resource. For more information, see Scriptrunner documentation.
Dynamically Direct Users to Request Types with ScriptRunner
This use case is an example of integration between Theme Extension for Jira Service Management and an external app, in this case, ScriptRunner.
The objective is to run a ScriptRunner script in Theme Extension for Jira Service Management that will check what group a customer is in, A or B, and direct them to to the appropriate request type group via URL.
Steps
Add the following scripts in ScriptRunner:
- The ScripRunner script presented below gets the path of the customer and returns the path to which they should be redirected. A REST endpoint is defined.
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.json.JsonBuilder
import groovy.transform.BaseScript
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.RendererManager
import com.atlassian.servicedesk.api.requesttype.RequestTypeService
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response
@WithPlugin("com.atlassian.servicedesk")
@BaseScript CustomEndpointDelegate delegate
getRedirect(httpMethod: "GET") { MultivaluedMap queryParams, String body ->
def authContext = ComponentAccessor.getJiraAuthenticationContext();
def groupManager = ComponentAccessor.getGroupManager();
def currentPath = queryParams.get("currentPath");
if(currentPath.get(0).toString().endsWith("theme/portal/1")) {
if(groupManager.isUserInGroup(authContext.getLoggedInUser(), "Group A")) {
return Response.ok("/plugins/servlet/theme/portal/1/group/2").build();
} else if(groupManager.isUserInGroup(authContext.getLoggedInUser(), "Group B")) {
return Response.ok("/plugins/servlet/theme/portal/1/group/1").build();
}
}
return Response.ok("").build();
}
- The ScriptRunner script presented below will execute the script from Step 1 in the backend and check whether a customer should be redirected or not. Customers from group A will be directed to to request types from group 2. Customers from group B will be, in turn, directed to request types from group 1.
function httpGetAsync(url, callback) {
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function () {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
callback(xmlHttp.responseText);
}
xmlHttp.open("GET", url, true);
xmlHttp.send(null);
}
(function () {
httpGetAsync(AJS.contextPath() + "/rest/scriptrunner/latest/custom/getRedirect?currentPath=" + window.location.pathname,
function (url) {
if (!!url) {
window.location.replace(url);
}
}
)
})();
theme-extension-view-portal
as web resource in ScriptRunner. For more information, see ScriptRunner documentation.Dynamically Fill the Announcement Banner with ScriptRunner
This use case is an example of integration between Theme Extension for Jira Service Management and an external app, in this case, ScriptRunner.
The objective is to run a ScriptRunner script in Theme Extension for Jira Service Management that will dynamically display custom announcement banners in Help Center, specific to selected request types.
Steps
Add the following Scripts to ScriptRunner:
- The ScriptRunner script presented below defines the REST endpoint and returns HTML content for the announcement banner.
getAnnouncementBanner(httpMethod: "GET") { MultivaluedMap queryParams, String body ->
return Response.ok("<h1>Announcement banner header</h1><p>Announcement banner description</p>").build();
}
- The ScriptRunner script presented below inserts the HTML content returned by the script from Step 1 into the announcement banner, identified as
announcement-banner-html-content
.
function httpGetAsync(url, callback) {
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function () {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
callback(xmlHttp.responseText);
}
xmlHttp.open("GET", url, true);
xmlHttp.send(null);
}
(function () {
const addContent = function () {
const announcementBanner = document.getElementById("theme-announcement-banner-html-content");
if (announcementBanner) {
clearInterval(checkAnnouncementBannerExists);
httpGetAsync(AJS.contextPath() + "/rest/scriptrunner/latest/custom/getAnnouncementBanner",
function (content) {
announcementBanner.innerHTML = content;
}
)
}
}
const checkAnnouncementBannerExists = setInterval(addContent, 1000);
})();
theme-announcement-banner
for the entire announcement banner element.theme-extension-view-portal
as web resource in ScriptRunner. For more information, see ScriptRunner documentation.If you can’t find the answer you need in our documentation, raise
a support request.
Include as much information as possible to help our support team resolve your issue faster.