Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How do I discover the Field Renderer used by a Custom Field in JIRA via a remote API?

Paul Curren
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 4, 2012

I'm working on the jiraissues macro in Confluence that will let you list issues from JIRA in a table in Confluence.

The problem I have is that I have no way of knowing if custom fields in the response are using the Default Text Renderer or the Wiki Style Renderer. The only safe assumption is to assume text and HTML escape the field values. Of course for fields that have been rendered this does not lead to the display you would hope for.

The issue data is retrieved from the XML 'API' e.g.

http://<server>/sr/jira.issueviews:searchrequest-xml/temp/SearchRequest.xml?jqlQuery=<someQuery>&tempMax=1000&pager/start=0

Custom fields are returned like -

&lt;customfields&gt;
&lt;customfield id="customfield_10103" key="com.atlassian.jira.plugin.system.customfieldtypes:textarea"&gt;
&lt;customfieldname&gt;ReleaseNote&lt;/customfieldname&gt;
&lt;customfieldvalues&gt;
&lt;customfieldvalue&gt;
&amp;lt;ol&amp;gt;
	&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;bold&amp;lt;/b&amp;gt;&amp;lt;/li&amp;gt;
	&amp;lt;li&amp;gt;&amp;lt;em&amp;gt;italics&amp;lt;/em&amp;gt;&amp;lt;/li&amp;gt;
	&amp;lt;li&amp;gt;&amp;lt;h3&amp;gt;&amp;lt;a name=&amp;quot;headings&amp;quot;&amp;gt;&amp;lt;/a&amp;gt;headings&amp;lt;/h3&amp;gt;&amp;lt;/li&amp;gt;
	&amp;lt;li&amp;gt;^superscript&amp;lt;/li&amp;gt;
	&amp;lt;li&amp;gt;
&lt;/customfieldvalue&gt;
&lt;/customfieldvalues&gt;
&lt;/customfield&gt;

How do I discover the way JIRA is handling a custom field so I can do the same?

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
JamieA
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.
January 4, 2012

Pretty sure this information is not available in any of the multifarious remote APIs... I guess you could add a new API to jira to return this information, or possibly add a new API that returns the values pre-escaped/formatted.

There are other possible renderers too apart from plain text and wiki markup, which are provided by plugins... although probably rarely enough used for you not to worry about them. But if that did concern you then the second option might be the best...?

3 votes
Wojciech Seliga
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.
January 4, 2012

In JIRA 5.0 land you could use new expand "renderedFields" which will give you fully rendered markup regardless of raw text (still available fields section)

E,g, <base url>/rest/api/latest/issue/<ISSUE-KEY>?expand=renderedFields would give you both raw and rendered values. AFAIK the type of rendered used is still not exposed, but if you want to handle just Text Rendered vs. Wiki Style Rendered, then you could just see if an opening HTML tag (usually <p>, <ul> or similar) is preceding field value in renderedFields section which would usually (i.e. always unless some other pluggable renderers are used) mean wiki renderer used there. For text renderer the value of given field in renderedFields section starts with pure text or \r if the first line was empty.

In versions prior to 5.0 you could use ?expand=html to achieve something similar.

Paul Curren
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 5, 2012

Thanks.

I'm a little reluctant to try and automatically recognise HTML from the start of the field. Erroneous matches could lead to be outputting something which is actually broken HTML and potentially break the display of the page completely in Confluence.

I guess I could run 'suspected' HTML through CyberNeko to ensure that it is valid but this is quite a bit of processing to be doing for potentially a large number of issues.

I think ultimately my best solution will be the inelegant approach of asking the macro user to decide what to do with individual fields. I'm discussing this over on the original JIRA issue.

TAGS
AUG Leaders

Atlassian Community Events