Forums

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

Get description-field of a JIRA issue as HTML using Groovy.

Andreas Dahlberg August 7, 2018

Hi!

I have written the following Groovy-script using Scripted fields:

 

------------------------------

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.fields.FieldManager;
import com.atlassian.jira.issue.RendererManager;


def rendererManager = ComponentAccessor.getComponent( com.atlassian.jira.issue.RendererManager.class)
def fieldLayoutItem = ComponentAccessor.getFieldLayoutManager().getFieldLayout(issue).getFieldLayoutItem("description")
def renderer = rendererManager.getRendererForField(fieldLayoutItem)
String desc = renderer.render(issue.getDescription(), null)

return desc

--------------------------------

which fetches the description-field in a JIRA issue and renders it as HTML. However, some of the descriptions contain images and these are not shown correctly. These pictures are completely empty. Is there a way to fix this?

2 answers

1 accepted

3 votes
Answer accepted
Tuncay Senturk _Snapbytes_
Community Champion
August 7, 2018

Hi Andreas,

fieldLayoutItem was defined in your code.

 And you're right about the latter one, it has three args.

Assuming you have the issue, the final code should be like this:

import com.atlassian.jira.issue.fields.NavigableField
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.fields.FieldManager;
import com.atlassian.jira.issue.RendererManager;


def fieldLayoutItem = ComponentAccessor.getFieldLayoutManager().getFieldLayout(issue).getFieldLayoutItem("description")
Field field = fieldManager.getField("description")
NavigableField navigableField = (NavigableField)field
return navigableField.getColumnViewHtml(fieldLayoutItem, new HashMap(), issue)
0 votes
Tuncay Senturk _Snapbytes_
Community Champion
August 7, 2018

I'm not sure but please try below code. I did not test it, just give it a try

It may give a clue

 

import com.atlassian.jira.issue.fields.NavigableField

Field field = fieldManager.getField("description")
NavigableField navigableField = (NavigableField)field
return navigableField.getColumnViewHtml(fieldLayoutItem)

Andreas Dahlberg August 7, 2018

Thanks for answering so quickly.

I can't see that you have defined the variable "fieldLayoutItem" anywhere. Also, from the API it seems as if the method getColumnViewHtml takes 3 parameters and not one.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events