Display panel in a script field (ScriptRunner)
Prerequisites:
ScriptRunner running on your Jira.
Let's say you have the following Elements Checklist panel structure:
You want to get your panel content and display it in the issue navigator, a Jira dashboard or even have it in your PDF exports
You can use the following script in a script field:
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.plugin.PluginAccessor;
PluginAccessor pluginAccessor = ComponentAccessor.getPluginAccessor();
pluginAccessor.getClassLoader().findClass("com.valiantys.software.elements.api.ElementsException");
// All Class requirements
Class panelRefClass = pluginAccessor.getClassLoader().findClass("com.valiantys.software.elements.api.model.PanelRef");
Class issueRefClass = pluginAccessor.getClassLoader().findClass("com.valiantys.software.elements.api.model.IssueRef");
Class panelRenderingServiceClass = pluginAccessor.getClassLoader().findClass("com.valiantys.software.elements.api.render.PanelRenderingService");
def panelRenderingService = ComponentAccessor.getOSGiComponentInstanceOfType(panelRenderingServiceClass);
def PANEL_NAME = "Quote"; // TO EDIT
try {
// Get panel
def panel = panelRefClass.byName(PANEL_NAME);
// Generate and return the HTML
return panelRenderingService.renderPanel(issue,panel);
} catch (Exception e) {
// You can log an Exception - or fail silently
return '';
}
You can even customize the CSS of the css table - in this example we show how to generate tables with a Confluence style (useful if you want to display them in a Jira issue macro in a confluence table):
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.plugin.PluginAccessor;
PluginAccessor pluginAccessor = ComponentAccessor.getPluginAccessor();
pluginAccessor.getClassLoader().findClass("com.valiantys.software.elements.api.ElementsException");
// All Class requirements
Class panelRefClass = pluginAccessor.getClassLoader().findClass("com.valiantys.software.elements.api.model.PanelRef");
Class issueRefClass = pluginAccessor.getClassLoader().findClass("com.valiantys.software.elements.api.model.IssueRef");
Class panelRenderingServiceClass = pluginAccessor.getClassLoader().findClass("com.valiantys.software.elements.api.render.PanelRenderingService");
Class defaultCssClassProviderClass = pluginAccessor.getClassLoader().findClass("com.valiantys.software.elements.api.render.DefaultCssClassProvider");
Class renderOptionsClass = pluginAccessor.getClassLoader().findClass("com.valiantys.software.elements.api.render.RenderOptions");
def panelRenderingService = ComponentAccessor.getOSGiComponentInstanceOfType(panelRenderingServiceClass);
def defaultCssClassProvider = defaultCssClassProviderClass.newInstance();
def issueRef = issueRefClass.byId(issue.getId());
def renderOptions = renderOptionsClass.newInstance();
def PANEL_NAME = "Quote"; // TO EDIT
defaultCssClassProvider.setTableClass("confluenceTable");
defaultCssClassProvider.setCellClass("confluenceTd");
defaultCssClassProvider.setHeaderClass("confluenceTh");
renderOptions.withCssClassProvider(defaultCssClassProvider);
try {
// Get panel
def panel = panelRefClass.byName(PANEL_NAME);
// Generate and return the HTML
return panelRenderingService.renderPanel(issueRef,panel, renderOptions);
} catch (Exception e) {
// You can log an Exception - or fail silently
return '';
}