JEMH velocity template - get custom field value

Raynard Rhodes
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.
March 2, 2021

I thought this would be simple, but a custom fields value will not display in the template. 

I've attempted:

$issue.getCustomFieldValue('customfield_###)

#set( $test = $customFieldManager.getCustomFieldObject("customfield_###"))
#if($issue.getCustomFieldValue($test))
$stringUtils.leftPad($test.name, $padSize): $issue.getCustomFieldValue($test)
#end

 

with no luck. I've reviewed https://docs.atlassian.com/software/jira/docs/api/8.5.4/ but am still not able to render the custom field value. The custom field itself displays all the project roles of a project, so it's always populated.

2 answers

0 votes
Mike Harrison _The Plugin People_
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.
March 8, 2021

Hi Raynard,

For custom fields with simple string values, something like this should render:


$issue.getCustomFieldValue('customfield_10200')

or

#set($cf = $customFieldManager.getCustomFieldObject('customfield_10200'))
$cf.getValue($issue)

Please ensure that the custom field ID in your template is correct. Also, if you are using this template in an issue workflow post-function, make sure that the notification post-function is ordered to fire after re-indexing has occurred.

You can break your template down in order to debug it:

#set ($cfId = 'customfield_10200')
#set($cf = $customFieldManager.getCustomFieldObject($cfId))
#if ($cf)
Found custom field $cf.getName()
#set ($cfVal = $cf.getValue($issue))
#if ($cfVal)
It has value: $cfVal
#else
It has no value
#end
#else
No custom field found for ID: $cfId
#end
0 votes
Boris Berenberg - Atlas Authority
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.
March 5, 2021

We make picking custom fields in templates super easy in Notification Assistant for Jira you can see an example at https://atlasauthority.atlassian.net/wiki/spaces/NAFJ/pages/1344667725/Create+Email+Template

Suggest an answer

Log in or Sign up to answer