Is it possible to access Asset object labels in batched mails templates?

Stefan Stadler
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.
August 7, 2024

Hi all,

I am trying to modify the mail content and switch to batched emails instead of single mails for every update.

Following the guide (Adding custom fields to email (atlassian.com))

Under step 2, HTML format, step 4, we can see the following listed:

 

#set ($customfield = $customFieldManager.getCustomFieldObject("customfield_10000"))

This appears to be not working for batched mails as I am not getting any response out of this.

I understand, that in batched emails, we can access the custom field values as follows:

#foreach ($value in $customFields)

   #if(${value.getValue()})

      $escape.apply($value.getValue())

   #end

#end

This is working fine, however, in case of Asset objects, I am getting an array back and also including the key.

Is it possible to get the labels only in this case?

Thanks!

Stefan

2 answers

1 accepted

0 votes
Answer accepted
Stefan Stadler
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.
August 9, 2024

Even if I did not find a way to access the labels directly, I have managed to display the values only and also remove the [ ] around the array values. 

This is how I solved it in the template:

<tr>
<td class="updates-diff-label">
$escape.apply($value.getName()):
</td>
#set ($val = $value.getValue().replaceAll("\s*\([A-Za-z]+-\d+\)",""))
<td class="updates-diff-content">
#if(${val.startsWith("[")})
#set ($val = $val.replaceAll("^\[|\]$", ""))
#end
$escape.apply($val)
</td>
</tr>

Essentially, I first replaced all object keys in the first set directive using regex. 

After this, if the string starts with a [, I am replacing the first [ and the last ] also using regex.

Using the classes for the td tags allows to catch up with the existing format of batched emails.

This works like a charm. 

Hope this helps others as well :)

Stefan

0 votes
Dick
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.
August 7, 2024

Hi Stefan,

Labels are in itself an array of values

Stefan Stadler
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.
August 7, 2024

Hi Dick,

thanks for letting me know. Do you know, how I can access those within the velocity template?

Thanks!

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
9.4.1
TAGS
AUG Leaders

Atlassian Community Events