Get customfield value based on field name for email templates

currently we are getting custom field values based on custom field IDs - Is there a way to get custom field values based on custom field name?

This is required because we have more than one JIRA instances and have different custom field ID's.

$issue.getCustomFieldValue("customfield_10011")

6 answers

This widget could not be displayed.

Hi Srilatha,

This code works for me in Email Template field used in the Script Listener "Send a custom e-mail":

 

<b>Aplicación afectada:</b> <%out <<issue.getCustomFieldValue(componentManager.getCustomFieldManager().getCustomFieldObjectByName("CI afectado")) %> 

 

"CI Afectado" is the name of a customfield

 

Regards,

 

Begoña

This widget could not be displayed.

Thank you Begona for your reply..

I have used following in my email templates, but still values are not rendered. Is it possible for you to send the whole syntax you are using? and do you have to import anything?

<%out <<issue.getCustomFieldValue(componentManager.getCustomFieldManager().getCustomFieldObjectByName("Equipment Name")) %>

 

<%out $issue.getCustomFieldValue(componentManager.getCustomFieldManager().getCustomFieldObjectByName("Equipment Name")) %>

This widget could not be displayed.

For more information about how to write the email template see:

http://docs.codehaus.org/display/GROOVY/Groovy+Templates#GroovyTemplates-GStringTemplateEngine

 

My complete e-mail template (it works for me if the customfields are configured belonging to the correct project):

 

<hr align="left" noshade="noshade" size="2" width="80%" />
<b>Código de asunto:</b> <% out <<issue.key %><br/>
<b>Tipo de asunto:</b> <% out <<issue.issueType?.name %><br/>
<% if(issue.getCustomFieldValue(componentManager.getCustomFieldManager().getCustomFieldObjectByName("Datos del solicitante"))) { %>
<b>Solicitante:</b> <%out <<issue.getCustomFieldValue(componentManager.getCustomFieldManager().getCustomFieldObjectByName("Datos del solicitante")) %><br/>
<% } %>
<% if(issue.getCreated()) { %>
<b>Fecha de creación:</b> <% out << issue.getCreated().format('dd-MM-yy HH:MM') %><br/>
<% } %>
<b>Aplicación afectada:</b> <%out <<issue.getCustomFieldValue(componentManager.getCustomFieldManager().getCustomFieldObjectByName("CI afectado")) %> <br/>
<hr align="left" noshade="noshade" size="2" width="80%" />
<b>Resumen:</b> <% out << issue.summary %><br/>
<% if(issue.description) { %>
<b>Descripción:</b> <% out << issue.description.replace("\n","<p/>") %>
<% } %>
<hr align="left" noshade="noshade" size="2" width="80%" />
<% if(issue.getResolutionDate()) { %>
<b>Fecha de la desestimación:</b> <% out << issue.getResolutionDate().format('dd-MM-yy HH:MM') %><br/>
<% } %>
<% if(issue.getCustomFieldValue(componentManager.getCustomFieldManager().getCustomFieldObjectByName("Motivo de la Desestimación"))) { %>
<b>Motivo de la desestimación:</b> <% out << issue.getCustomFieldValue(componentManager.getCustomFieldManager().getCustomFieldObjectByName("Motivo de la Desestimación")).replace("\n","<p/>") %><br/>
<% } %>
<hr align="left" noshade="noshade" size="2" width="80%" />
<br/>

This widget could not be displayed.

Thank you but looks like you are using groovy(script runner) email templates?

we are trying to update/add velocity email templates in JIRA installation (atlassian-jira\WEB-INF\classes\templates\email) 

This widget could not be displayed.

You're rigth Srilatha, I'm using groovy. I've never used velocity.I'm sorry

 

Begoña

This widget could not be displayed.

For including in an HTML velocity template I use something like the code below. You could use a different customFieldManager method to get the field by name but be careful that you only have one custom field with that name defined

 

#set ($cf = $customFieldManager.getCustomFieldObject('customfield_10371'))
#if ($cf)
  #set ($projectObject = $issue.getProjectObject())
  #set ($issueTypeObject = $issue.getIssueTypeObject())
  #set ( $idArray = [$issueTypeObject.id] )

  #if ( $cf.isInScope($projectObject, $idArray) )
    #set ($currValue = $cf.getValue($issue))
    #if ($currValue &amp;&amp; ! $currValue.equals(""))
&lt;tr valign="top"&gt;
    &lt;td style="color:${textColour};font-family:${textFontFamily};font-size:${textSize};padding:0 10px 10px 0;white-space:nowrap;"&gt;
        &lt;strong style="font-weight:normal;color:${textSubtleColour};"&gt;$cf.name:&lt;/strong&gt;
    &lt;/td&gt;
    &lt;td style="color:${textColour};font-family:${textFontFamily};font-size:${textSize};padding:0 0 10px 0;width:100%;"&gt;
      $currValue
    &lt;/td&gt;
&lt;/tr&gt;
    #end
  #end
#else
&lt;tr&gt;&lt;td&gt;unknown field&lt;/td&gt;&lt;/tr&gt;
#end

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

189 views 3 0
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you