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
Community moderators have prevented the ability to post new answers.
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() ) <li>Key: $optionKey -> Value: $issue.getCustomFieldValue("customfield_11406").get($optionKey)</li> #end
The above should work for JIRA 6.2.x
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.
<tr> <th>#text($issue.getCustomField("customfield_10800").name):</th> <td> foreach( $optionKey in $issue.getCustomFieldValue("customfield_10800").keySet()) $issue.getCustomFieldValue("customfield_10800").get($optionKey) #end </td> </tr>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No worries, glad it's worked out now for you as well Frank :-D
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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")) >$stringUtils.leftPad("OEM/Device", $padSize): $cfValue.getFirstValueForNullKey() / $cfValue.getFirstValueForKey("1") #end
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Frank,
Unfortunately this code did not work. Did you try this in JIRA 5?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.