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:
theme-extension-view-portal
as web resource. For more information, see Scriptrunner documentation.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 the appropriate request type group via URL.
Steps
Add the following scripts in ScriptRunner:
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();
}
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.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:
getAnnouncementBanner(httpMethod: "GET") { MultivaluedMap queryParams, String body ->
return Response.ok("<h1>Announcement banner header</h1><p>Announcement banner description</p>").build();
}
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.