Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

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

Having read about the ability to modify the email templates in RTC (https://jazz.net/library/article/957) 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:
Subject:
[Work Item ${workItem.identifier}] #if(${change.isCreation}) New: #end #if(${workItem.get("com.ibm.team.workitem.apar.aparNumber")})(${workItem.get("com.ibm.team.workitem.apar.aparNumber")}) #end ${workItem.summary} ${recipientRelation.abbreviation}

Body:
Web UI: ${workItem.URL}

Id:            ${workItem.identifier}
Type:          ${workItem.type}
#if(${workItem.get("com.ibm.team.workitem.apar.aparNumber")})
APAR:          ${workItem.get("com.ibm.team.workitem.apar.aparNumber")}
#end
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?

0 votes



One answer

Permanent link
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("com.ibm.team.workitem.apar.aparNumber")}
#end

Summary:       ${workItem.title}

0 votes

Comments

 nice workaround!!

Your answer

Register or log in to post your answer.

Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 12,019

Question asked: Feb 12 '14, 5:28 a.m.

Question was seen: 4,728 times

Last updated: Feb 19 '14, 1:52 p.m.

Confirmation Cancel Confirm