It's all about the answers!

Ask a question

Modifying email template to include a custom attribute results in AssertionFailedException when the attribute doesn't exist in built-in types

Rachel Alderman (331418) | asked Feb 12 '14, 5:28 a.m.
Having read about the ability to modify the email templates in RTC ( I thought I'd try and include one of the custom attributes in my emails. I modified the "Work item change notification" template to include:
[Work Item ${workItem.identifier}] #if(${change.isCreation}) New: #end #if(${workItem.get("")})(${workItem.get("")}) #end ${workItem.summary} ${recipientRelation.abbreviation}

Web UI: ${workItem.URL}

Id:            ${workItem.identifier}
Type:          ${workItem.type}
APAR:          ${workItem.get("")}
Summary:       ${workItem.title}
Using the "Template Test" tool, I can select the custom work item types that contain this attribute and the emails are as expected. However, if I select a built in work item type, that doesn't contain the attribute, the tool shows I have an error in the template:
Method invocation exception
Method get() threw AssertionFailedException: assertion failed:
I deliberately put the workItem.get in the #if to try to test for its existence before using it to display, to try to avoid this scenario. Looking at the conditionals section of the Velocity Template language, I believe that the #if statement should evaluate to false if the value is a null value or false and then there should be no output - this is what I expected to happen if the workItem.get() expression failed.

The preview shows that the value isn't included, but I don't want to put this email template change live until I know its not going to cause errors for all the built in work item types. Where would the template error show? Is there a boolean method for testing whether an attribute exists that could be used in the #if statement rather than the get method?

Any suggestions?

One answer

permanent link
Rachel Alderman (331418) | answered Feb 19 '14, 10:32 a.m.
Worked around the problem, by testing for the specific work item type:

Id:            ${workItem.identifier}
Type:          ${workItem.type}
#if($workItem.type == "APAR")
APAR:          ${workItem.get("")}

Summary:       ${workItem.title}

sam detweiler commented Feb 19 '14, 1:52 p.m.

 nice workaround!!

Your answer

Register or to post your answer.