Script Runner: Adding lozenge to HTML scripted field to show linked issue status.

Truss Robinson February 28, 2019

What I've done so far all seems to be working well:

  1. I started with this Adaptavist tutorial (with near zero scripting experience).
  2. Added in some custom field values.
  3. Added in an if statement to only list linked issues of a certain type

What is left is that I want to replace my 'Disposition' column with the lozenge instead of the plain text status.

What the table currently publishes as:

table.PNG

 

What I'd like to appear in the last column:

lozenges.PNG

 

Additionally, I'd like to have them not truncated.

An alternative solution I'd also be open to (if it is easier to implement) is to add another column that uses the getStatusCategory() to simply list the To Do/In Progress/Done status lozenge and have the disposition remain as plain text.

The current code:


import com.atlassian.jira.component.ComponentAccessor
import groovy.xml.MarkupBuilder
import org.apache.log4j.Logger
import org.apache.log4j.Level

def log = Logger.getLogger("com.DRTable.GenerateTable")
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def links = issueLinkManager.getOutwardLinks(issue.id)
def customFieldManager = ComponentAccessor.getCustomFieldManager()

log.setLevel(Level.DEBUG)

def writer = new StringWriter()
def xml = new MarkupBuilder(writer)

if(!links){
return null
}

xml.style(type:"text/css",
'''
#scriptField, #ScriptField *{
border: 1px solid black;
}

#scriptfield{
border-collapse: collapse;
}
th {text-align:center
}
td {
padding: 10px;
}
tr:nth-child(even) {
background-color: #eee;
}
tr:nth-child(odd) {
background-color: #fff;
}
''')

xml.table(id:"scriptField"){
tr{
th("Identity")
th("Type")
th("Catagory")
th("Severity")
th("Summary")
th("Disposition")
}
links.each {issueLink ->
def linkedIssue = issueLink.destinationObject
def issueID = linkedIssue.id
def cfType = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Comment Type'}
def cfSeverity = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Severity'}
def cfCategorization = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Categorization'}
log.debug issueID
log.debug linkedIssue.issueTypeId
log.debug linkedIssue.status
if(linkedIssue.issueTypeId == "10410"){
tr{
td(linkedIssue.key.toString())
td(linkedIssue.getCustomFieldValue(cfType))
td(linkedIssue.getCustomFieldValue(cfCategorization))
td(linkedIssue.getCustomFieldValue(cfSeverity))
td(linkedIssue.summary.toString())
td(linkedIssue.status.getName().toString())
}
}}
}

return (writer.toString())

 

 

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events