How to insert dynamic table in script fragment/web panel

nallu July 17, 2018

Hi,

In JIRA, I am trying to create a Web Panel which will display the linked epics details in HTML format as below,

KeySummaryStatusTypeFix-Version
JIRAKey-123Linked Epic - 1NewEpic[Label-test]

 

I referred below sites and did this,

Advanced Scripted Field - https://scriptrunner.adaptavist.com/latest/jira/recipes/misc/table-custom-field.html

Web Panel - https://scriptrunner.adaptavist.com/latest/jira/fragments/WebPanel.html

 

Here is my code. It doesn't display the content in Issue View screen.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.search.SearchProvider
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
import groovy.xml.MarkupBuilder

Issue issue = context.issue as Issue

//Get current Key
def currKey = issue.getKey()

//Query for all epics where feature link = current key
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchProvider = ComponentAccessor.getComponent(SearchProvider)
def issueManager = ComponentAccessor.getIssueManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getUser()

def queryString = 'type=epic and "Feature Link" = ' + currKey
def query = jqlQueryParser.parseQuery(queryString)
def results = searchProvider.search(query, user, PagerFilter.getUnlimitedFilter())


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


if(!results){
"N/A"
}


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

#scriptField{
border-collapse: collapse;
}
th, td {
padding: 5px;
text-align: center;
}
''')

xml.table(id:"scriptField"){
tr{
th("Key")
th("Summary")
th("Status")
th("Type")
th("Fix-Version")
}

results.getIssues().each { documentIssue ->
tr{
td(documentIssue.key.toString())
td(documentIssue.summary.toString())
td(documentIssue.status.getName().toString())
td(documentIssue.getIssueType().getName())
td(documentIssue.getFixVersions())
}
}
}

return (writer.toString()) 

 

Hence, I tried to display the simple content as a div. I just removed MarkupBuilder part from the above code and wrote it as simple as below.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.search.SearchProvider
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
import groovy.xml.MarkupBuilder

Issue issue = context.issue as Issue

//Get current Key
def currKey = issue.getKey()


writer.write("<div style='background-color: yellow; text-align: center'>" +
" ${currKey} - Testing </div>")

 

In the second case, it is displaying the web-panel with data correctly as below

 

Screen Shot 2018-07-17 at 4.07.18 PM.png

 

Can anyone look into my first code and tell me what i am doing wrong over there? I feel like, this is not working for 'MarkuuBuilder'. 

Is there any other way to display the data in a simple and need HTML table. 

Please help me out. 

3 answers

1 accepted

1 vote
Answer accepted
Mark Markov
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.
July 17, 2018

Hello @nallu

Im not shure that MarkupBuiler wil work too.

You can look at my example here, how to write html table and fill it with info.

If you need more detailed info, feel free to ask!

Hope it helps!

nallu July 19, 2018

Thanks a lot for sharing your code @Mark Markov

Ilya Stekolnikov
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.
March 17, 2022
0 votes
Dang Thi Thuy Tien
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.
November 28, 2019
0 votes
Christof Hurst _kreuzwerker_ August 8, 2019

I think you can just use official writer object and give xml markup as string to the write() function

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events