The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Show custom field in ScriptRunner web panel

JOJ
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
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

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
PD Sheehan
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 Champions.
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
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
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