Show custom field in ScriptRunner web panel

JOJ April 13, 2023

Hello community,

 

I want to display an existing custom field in a web panel. I use the “Show a web panel” function from ScriptRunners Script Fragments.

In my case it’s a calculated progress field from the sumUp plugin.

This is what I want:

Web_panel.png

This is what I get:

Error.png

I have found an old post in which it says that it’s not possible to display custom fields in a web panel. Maybe that has changed in the meantime.

Maybe (or most likely) there is a bug in my script because I don't know Groovy that well.

This is the script I use:


import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.RendererManager

def issue = context.issue as Issue
String customfield = "customfield_19800"

def rendererManager = ComponentAccessor.getComponent(RendererManager)
def fieldLayoutItem = ComponentAccessor.getFieldLayoutManager().getFieldLayout(issue).getFieldLayoutItem(customfield)
def renderer = rendererManager.getRendererForField(fieldLayoutItem)
String value = issue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObject(customfield))

writer.write(renderer.render(value, issue.getIssueRenderContext()))

 

Best regards,
Jo

1 answer

0 votes
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 14, 2023

I'm not familiar with the SumUp plugin and how it stores its values.

But it would seem that when you return "value" from getCustomFielValue, it returns an object of some kind that doesn't have an automatic "toString" method.

If you're not sure what that value is, you can output its class as a debug step.

writer.write(renderer.render(value.getClass(), issue.getIssueRenderContext()))

Then see if the sumUp plugin has documentation for how to render that class.

If they don't you can use Groovy metaClass to get an idea of what methods that object might have:

writer.write(renderer.render(value.metaClass.methods*.name.sort().unique(), issue.getIssueRenderContext()))
JOJ May 9, 2023

Hello Peter-Dave,

sorry for the late reply. I was on vacation. I will test this with my colleagues.

Best regards,

Jo

Suggest an answer

Log in or Sign up to answer