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

Cascading select custom field in JIRA 5 email templates

Pranjal Shukla May 13, 2012

Hello friends,

Velocity code written for JIRA 4.2.4 to fetch cascading select field in an email does not work. Any suggestions to make it work. We are using the below mentioned.

#if($issue.getCustomFieldValue("customfield_10013"))
<tr>
    <td valign="top" width="20%" class="Side_Heading"><p  class="Normal"><strong>SBU and LOB:</strong></p></td>
    <td valign="top" width="80%"><p  class="Normal">
        #set ($value = $issue.getCustomFieldValue("customfield_10013"))
        #if ($value.getValuesForKey(null) && $value.getValuesForKey(null).isEmpty() == false)
        #set ($parentValue = $value.getValuesForKey(null).iterator().next())
        #end
        #if ($value.getValuesForKey('1') && $value.getValuesForKey('1').isEmpty() == false)
        #set ($childValue = $value.getValuesForKey('1').iterator().next())
        #end
        ##value: $value
        ##value.cl: $value.class
        ##selpar: : $parentValue.class :
        ##selchild: : $childValue.class :
        #if ($parentValue)
        $!parentValue.value
#if ($childValue)
- $!childValue.value
        #end
        #end
        </p>
        </td>
</tr>
#end

6 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
ohernandez
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 19, 2014

Hi all,

<tt>getCustomFieldValue</tt> is a method on the <tt>Issue</tt> object, specified in the api at https://docs.atlassian.com/jira/latest/com/atlassian/jira/issue/Issue.html

Accordingly, the return value is defined as:

A custom field's value. Will be a List, User, Timestamp etc, depending on custom field type.

Knowing this, by invoking:

$issue.getCustomFieldValue("customfield_11406")

You are getting a <tt>Map<String, Option></tt> where <tt>null</tt> is the key for the parent option and <tt>1</tt> is the key for the child option.

In order to get these values individually it's only necessary to iterate over the Map, for instance:

#foreach( $optionKey in $issue.getCustomFieldValue("customfield_11406").keySet() )
    &lt;li&gt;Key: $optionKey -&gt; Value: $issue.getCustomFieldValue("customfield_11406").get($optionKey)&lt;/li&gt;
#end

The above should work for JIRA 6.2.x

0 votes
Frank Adam June 25, 2014

Doh!

I went through it again, and it wasn't the "end" text - that was just plain text for testing. But the custom field value I passed in wasn't right. I was missing the _ in the string. So YES! It's fixed. Thanks very much.

&lt;tr&gt;
   &lt;th&gt;#text($issue.getCustomField("customfield_10800").name):&lt;/th&gt;
   &lt;td&gt;
      foreach( $optionKey in $issue.getCustomFieldValue("customfield_10800").keySet())
         
         $issue.getCustomFieldValue("customfield_10800").get($optionKey)
      #end
   &lt;/td&gt;
&lt;/tr&gt;

ohernandez
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 26, 2014

No worries, glad it's worked out now for you as well Frank :-D

0 votes
Frank Adam June 19, 2014

Hi Oswaldo,

Thanks for the reply, but that still fails to work for me in JIRA 6.2. Here is what I have that does work:

#if($issue.getCustomFieldValue("customfield_10800"))
 
## Try workaround to extract the OEM and Device strings - They look like {null=Samsung, 1=i545} now in mail
#set( $sValue = $issue.getCustomFieldValue("customfield_10800").toString() )
#set( $sValue1 = $stringUtils.chop($sValue) )
#set( $oem1 = $stringUtils.substringBefore($sValue1, ',') )
#set( $oem2 = $stringUtils.substringAfter($oem1, '=') )
##
#set( $sub1 = $stringUtils.substringAfter($sValue1, ',') )                      
#set( $sub2 = $stringUtils.substringAfter($sub1, '=') )
 
<tr>
   <th>#text($issue.getCustomField("customfield_10800").name):</th>
   <td>$oem2 / $sub2</td>
</tr>
#end

I tried your suggestion - here is my exact code: 
 <tr> <th>#text($issue.getCustomField("customfield_10800").name):</th> <td> start. #foreach( $optionKey in $issue.getCustomFieldValue("customfield10800").keySet()) Key: $optionKey -> Value: $issue.getCustomFieldValue("customfield_10800").get($optionKey) #end end </td> </tr>

And with that, here's what you see: 
<th>OEM/Device:</th>
start. end
ohernandez
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 25, 2014

Hi Frank,

Another customer got my example to work for him so this is indeed strange...

The snippet with my modified suggestion does have an

end

missing the # before it, so this could perhaps be the problem? :-S

0 votes
Frank Adam May 20, 2013

Finally managed to upgrade to JIRA 5.2, and now my code listed above doesn't work either. The only thing that I can get to work is

>$stringUtils.leftPad($issue.getCustomField("customfield_10800").name, $padSize): $issue.getCustomFieldValue("customfield_10800")

Which looks horrible, but at least lists out the pair of values. I couldn't get anything else to work.

0 votes
Frank Adam June 26, 2012

I haven't been able to test in JIRA 5. I should have an upgrade to 5 in a couple of weeks. If there has been no other answer before then, I will post with what I have.

Anoop Wilson July 24, 2012

Hi Frank,

Any Updates?

Frank Adam July 24, 2012

Still waiting for the upgrade to 5 on our test instance. I'm told it should be happening this week, so I'm hopeful that I will have answers next week.

0 votes
Frank Adam June 4, 2012

Here's a slightly shorter method, that checks if the Custom Cascading Select Field is present, and then outputs the Field Name followed by the two values. In my case, the field is named "OEM/Device". I put this code into issuesummary.vm, which is why it is indented.

#if($issue.getCustomFieldValue("customfield_10800"))
#set( $cfValue = $issue.getCustomFieldValue("customfield_10800"))
&gt;$stringUtils.leftPad("OEM/Device", $padSize): $cfValue.getFirstValueForNullKey() / $cfValue.getFirstValueForKey("1")
#end

Pranjal Shukla June 11, 2012

Hi Frank,

Unfortunately this code did not work. Did you try this in JIRA 5?

Pranjal Shukla June 24, 2012

@Atlassian,

Anybody listening!!

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events