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
Community moderators have prevented the ability to post new answers.
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?
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Using <div> works! Thanks...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.