Script field breaks issue view

Mike Wells
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 22, 2015

Hi there,

I have a script field on my Issue View Screen. The purpose is to show an icon in place of text.

import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.index.IndexException;
import com.atlassian.jira.util.JiraDurationUtils;
import com.atlassian.jira.util.JiraDurationUtils.PrettyDurationFormatter;
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.issue.worklog.TimeTrackingConfiguration
import org.apache.log4j.Logger

Logger log = Logger.getLogger("com.onresolve.jira.groovy.PostFunction")
log.setLevel(org.apache.log4j.Level.DEBUG)
log.info("Starting GroovyScript TypeScriptedField")

Issue issue = issue


String htmlString = "<html><img src=\"http://jira.dsasystems.inc:8080/images/icons/issuetypes/ICON\" alt=\"ICON\" title=\"TITLE\"></html>";
String title = "";
CustomField observationType = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Observation Type")
CustomField type = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Type");

String observationTypeString = issue.getCustomFieldValue(observationType);
log.debug("Observation Type  = "+observationTypeString);
observationTypeString = (observationTypeString == null)?"":observationTypeString;
String icon = "";

if(observationTypeString.equals("Feature")){
    title = "Feature";
    icon = "newfeature.png"
}else if(observationTypeString.equals("Improvement")){
    title = "Improvement";
    icon = "improvement.png"
}else if(observationTypeString.equals("Defect")){
    title = "Defect";
    icon = "defect.png"
}else if(observationTypeString.equals("Bug")){
    title = "Bug";
    icon = "bug.png"
}else{
title = "Unclassified";
icon = "undefined.png"
}

htmlString = htmlString.replaceAll("ICON", icon);
htmlString = htmlString.replaceAll("TITLE", title);

return htmlString

This script is working in the sense it returns what is expected. However the Issue View screen fails to render correctly. This is true regardless of whether or not I return HTML or plain text. Only empty string or null prevent the issue from happening.

Here is a screenshot of the Issue View failing.

script-field-bug.png

There is nothing in the log file that suggests a problem, in fact the script seems to work fine, so I suspect the problem is not the script directly.

Script Runner Version: 3.0.16

JIRA Version: v6.4.6#64021-sha1:33e5b45

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
Sean Curtis
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 22, 2015

I'm not 100% sure, but it could be that you're appending an <html> element to the page. Why is your <img> wrapped in an <html> tag? That seems like a really bad thing to do. Can you try just making that a <div>, or removing it entirely, instead?

Mike Wells
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 22, 2015

You're probably right about the html tags being a bad idea, but I think this wad taken from an example. Either way I tested this by hard coding some plain text and the problem still occurs. I'll test with the div tag though, that would be interesting to see.

Mike Wells
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 23, 2015

Using <div> works! Thanks...

TAGS
AUG Leaders

Atlassian Community Events