It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to insert dynamic table in script fragment/web panel

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

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!

Thanks a lot for sharing your code @Mark Markov

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

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you