Message templates

Last modified 31 Oct 2022 20:07 +01:00
Since 4.5
This functionality is available since version 4.5.

Message template is an object that provides a template for the content of a message, i.e. a notification message. It specifies typical components of such a message - like subject, body and attachments. In addition to the defaultContent for the message, additional localized contents can be defined.

Message template structure

The logical structure of the message template is:

message templates class diagram

GUI configuration

You can define the message templates in GUI:

message templates gui list

The detail allows to enter the expressions for each content component:

message templates gui edit content

Expressions in the message template produce string results. For this reason, use of Velocity templates is a natural fit. Currently, the expressions must be still entered as an XML code, but there are tentative plans to make writing of templates easier, e.g. by copy/pasting HTML template for the message.

Expression example

An example of a body expression can look like this:

<script>
    <language>velocity</language>
    <code><![CDATA[The following changes were made for user <b>${requestee.name}</b>:
#* Executed deltas are too noisy + diving into its objectDelta is needed:
<ul>
#foreach ($delta in $event.focusContext.executedDeltas)
   <li>$delta.objectDelta.debugDump()</li>
#end
</ul>
*#
$event.focusContext.primaryDelta.debugDump()]]></code>
</script>

The template expression above demonstrates:

  • As mentioned, Velocity can be a better option for textual templates. Since midPoint 4.5 one can specify the language with the local part of the language URL - which is velocity in this case.

  • It is possible to iterate over collections with #foreach macro.

  • It is possible to comment out some parts - here the whole iteration is actually commented with #* …​ *# block.

Of course, it is possible to use script expression with any other supported language (e.g. Groovy), or you can use any other expression evaluator.