Forums

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

Custom email field not showing correct field value

Terry King April 10, 2012

In Jira 5.0 we have several custom fields. These customizations have always worked in the past in the html emails. Code below now is just showing garbarge like [com.atlassian.crowd.embedded.ofbiz.OfBizUser@b6b373d2] for the value rather than the jira user name that's stored in the field via the multi user picker. The other custom fields show the correct data in the html email. Any idea on what's going on?

#if ($issue.getCustomFieldValue("customfield_10131"))
<tr valign="top">
<td style="color:${textColour};font-family:${textFontFamily};font-size:${textSize};padding:0 10px 10px 0;white-space:nowrap;">
<strong style="font-weight:normal;color:${textSubtleColour};">
$stringUtils.leftPad($issue.getCustomField("customfield_10131").name, $padSize):
</strong>
</td>
<td style="color:${textColour};font-family:${textFontFamily};font-size:${textSize};padding:0 0 10px 0;width:100%;">
$issue.getCustomFieldValue("customfield_10131")
</td>
</tr>
#end

1 answer

1 vote
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.
April 10, 2012

Which bit is not working? It should be:

$issue.getCustomField("customfield_10131").name

which will prevent an error if the field has no value set. And are you sure this is a multi not a single user picker? This code should not work for a multi user picker. You need to iterate over the users calling .name on each one. I don't see how this worked previously.


Terry King April 10, 2012

In our Jira 4.2 production instance, below is the code that's in the issuessummary.vm for html templates and the email is showing the two users that were added to the issue as UAT asignments. I thought the same thing as well that it should have to be iterated through with a foreach..end statement. So I was just carrying the same change forward to 5.0. I can replace the code with the foreach..end statement but I'm not fully aware of the syntax for custom fields.

Email shows this:
UAT Assignments: [ceswift,tlking]

#if ($issue.getCustomFieldValue("customfield_10131"))
>$stringUtils.leftPad($issue.getCustomField("customfield_10131").name, $padSize): $issue.getCustomFieldValue("customfield_10131")
>
#end

Radu Dumitriu
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.
April 10, 2012

Terry, this is caused by a toString() overriden method. In Jira 5, this is missing and the default toString() method was called, producing the result you see.

So: either do what Jamie said, or "patch" jira class com.atlassian.crowd.embedded.ofbiz.OfBizUser with a nicer toString() method.

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.
April 10, 2012

That's what I thought at first, but surely the value should be a collection of OfBizUsers, not one.

Terry King April 11, 2012

I used the following in the issuecreated.vm for the html emails and it worked. Thanks.

#if ($issue.getCustomFieldValue("customfield_10131"))
<tr valign="top">
<td style="color:${textColour};font-family:${textFontFamily};font-size:${textSize};padding:0 10px 10px 0;white-space:nowrap;">
<strong style="font-weight:normal;color:${textSubtleColour};">
$stringUtils.leftPad($issue.getCustomField("customfield_10131").name, $padSize):
</strong>
</td>
<td style="color:${textColour};font-family:${textFontFamily};font-size:${textSize};padding:0 0 10px 0;width:100%;">
#foreach ($CustomField in $issue.getCustomFieldValue("customfield_10131"))
$CustomField.name,
#end
</td>
</tr>
#end

Suggest an answer

Log in or Sign up to answer