The Templating Application allows to invoke Velocity or MS Word DOCX templates with Process Data and if required converts the output into PDF format.
A template is a document, such as a personalized form letter/email/report that is sent to many customers. Templates allow business people to have more control regarding document content and format. Find more details in the following sections:
Apart from the common properties, the following property tabs are provided for a Templating application:
Figure: Properties - Templating Application
You can define parameters to access the data associated with the application.
The Templating Application only allows for one Output Parameter of type Text, which is
representing the response content of the Velocity Template invocation.
It allows for multiple Input Parameters. Input Parameters can be document or primitive/structured data,.
Click the
Add icon to add the parameters.
Primitive, choose the
Primitive Type from the provided drop-down list.Structured Data, choose the
Structured Type from the current model or another model from the provided drop-down list.Document, choose the according
Structured Type from the current model or another model from the provided drop-down list.To delete the parameters, select the added parameter and click the Delete
icon.
Figure: Properties - Parameters
In the Configuration tab, you specify the template source, format, content and output. It is also possible to indicate whether the template output should be converted into PDF format.
demo-project/WEB-INF/classes)ClassPath or
Repository is selected in the Source field.DOCX is selectedDocument is selectedIn the following example, an embedded template content is converted to PDF and attached to the process instance using the specified output file name.
Figure: Properties - Embedded Configuration
At runtime, the PDF attachment looks similar to the sample in the screenshot below:
Figure: PDF Template output sample
The template could be located in the class path as shown below:
Figure: Properties - Class Path Configuration
The following example uses embedded XML template content. The result is attached to the process instance using the specified output file name.
Figure: Configuration - Embedded XML template
Figure: XML document output
The following example uses embedded HTML template content. The result is converted into PDF format and attached to the process instance using the specified output file name.
Figure: Configuration - Embedded HTML template
Figure: HTML converted to PDF output
In case option Convert to PDF is not selected, the output document will be in HTML format.
Figure: HTML converted to PDF output
The following example uses a DOCX template. The result is converted into PDF format and attached to the process instance using the specified output file name.
Figure: Configuration - DOCX template configuration
The DOCX template file is located in the repository under the Root/artifacts/templates folder.
Figure: Template repository location
It is created using MS Word. Find a sample file below:
Figure: DOCX Sample template
A sample DOCX output converted to PDF format is shown below:
Figure: DOCX output converted to PDF format
In many situations, the end user would like to specify the Template and/or the Output Name dynamically (i.e. at runtime). This also allows the same templating application to be used with multiple template files at runtime.
Here are the main steps to follow:
Figure: Dynamic Template Configuration
If you want to provide a template file name and/or the output name dynamically through a structured data type, then use expressions such as: $simple{header.Person[template]} and/or $simple{header.Person[outputName]}.
Figure: Dynamic Template Configuration with SDT
To create Velocity templates in text, XML or HTML format, you can use your preferred text editor.
Figure: HTML Template
More details about the Velocity Template Language (VTL) could be found here.
MS Word DOCX templates can easily be created using MS Word by following these steps:
$person.firstName:

Figure: Select to add a field
$person.firstName in the Field name entry field. Merge fields are placeholder for
information such as name, address, etc.
Figure: DOCX Template Creation
«
». Note that in MS Word, the field content is not displayed in full length if it exceeds a certain
length. In that case you have to edit the field to see its full content.The following examples show how to process a data that contains a list of elements.
We define a project data type with the following structure:
Figure: Project structured Type with list of developers

Figure: Project Name and List of Developers sample
If you want to generate a list with the first name and last name of all structured data instances of developers, you have to loop over fields using Velocity syntax.
Prepare the template in MS Word by adding the following text containing an unordered and an ordered list:
Figure: Unordered and ordered list
Now create the following fields of type MergeField as described in section Creating MS Word DOCX Templates with the following entries as their field names:
$Project.name#foreach($developer in $Project.developers)

$developer.Firstname$developer.Lastname#endThe Word content now should look similar as in the below screenshot. Please note that in MS Word, the field content is not displayed in full length if it exceeds a certain length. You have to edit the field to see its full content.
Figure: Developers List Bullet and Numbering DOCX template
Find below the complete text including the Velocity scripts used in this sample:
Project: «$Project.name» Developer List: «#foreach($developer in $Project.developers)» . «$developer.Firstname» «$developer.Lastname»«#end» Developer List: «#foreach($developer in $Project.developers)» 1. «$developer.Firstname» «$developer.Lastname»«#end»
The generated MS Word DOCX document looks similar to the example in the following screenshot:
Figure: Developers List Bullet and Numbering DOCX output
In this example, two tables will be generated:
Prepare the template in MS Word by adding the following text and tables:
Figure: Plain text and tables
You can add colors to a row by selecting Borders and Shading from the Home menu. Select the Shading tab and choose a color.
Figure: Select a color for a row
Now add fields of type MergeField as described in section Creating MS Word DOCX Templates:
$Project.name@before-row#foreach($developer in $Project.developers)$developer.Firstname@after-row#end$developer.Lastname$developer.Email$developer.Salary followed by text "EUR"@before-row#foreach($developer in $Project.developers) #if(0 ==$velocityCount%2)$developer.Firstname@after-row#else$developer.Firstname@after-row#end #end$developer.Lastname$developer.Email$developer.Salary followed by text "EUR"The document now looks similar as below:

Figure: Developers Table DOCX template
Please note that in MS Word, the field content is not displayed in full length if it exceeds a certain length. You have to edit the field to see its full content. Find below an overview on the Velocity scripts used in this example:
Project: «$Project.name» Developer Table I | First Name | Last Name | Email | Salary | ---------------------------------------------------------------------------------------------------------------------------------- | «@before-row#foreach($developer in $Project.developers)» | «$developer.Lastname» | «$developer.Email» | «$developer.Salary»EUR | | «$developer.Firstname» | | | | | «@after-row#end» | | | | Developer Table II | First Name | Last Name | Email | Salary | ------------------------------------------------------------------------------------------------------------------------------------------------------------ | «@before-row#foreach($developer in $Project.developers) #if(0 ==$velocityCount%2)» | «$developer.Lastname» | «$developer.Email» | «$developer.Salary»EUR | | «$developer.Firstname» | | | | | «@after-row#else» | | | | ------------------------------------------------------------------------------------------------------------------------------------------------------------ | «$developer.Firstname» | «$developer.Lastname» | «$developer.Email» | «$developer.Salary»EUR | | «@after-row#end #end» | | | | ------------------------------------------------------------------------------------------------------------------------------------------------------------
The generated document looks similar as displayed in the screenshot below:

Figure: Tables of Developers
The core templating functionality is available via REST service.
The Templating REST service path is services/rest/templating as shown below.
http://localhost:8080/ipp-portal/services/rest/templating
It has a POST request with the following JSON payload:
classpath://myTemplate.vmrepository://myTemplate.vm: file located in Root/artifact/templates repository folderrepository://myFolder/myTemplate.docx: file located in Root/artifact/templates/myFolder folderrepository://artifacts/templates/myFolder/myTemplate.docx: file located in Root/artifact/templates/myFolder folderrepository://{urn:repositoryId:System}{jcrUuid}954e8bb0-5085-429d-9e59-60c21eb8fb47: document ID sample, it can be shown through the Document Repository view as below :
Figure: Document Details
"template": "Hello $customer.firstname $customer.lastname. Your request is approved"
"parameters": {
"customer": {
"firstname": "Peter",
"lastname": "Smith"
}
}
Find below a request sample:
{
"templateUri": "repository://letter.docx"
"format": "docx",
"pdf": true,
"parameters": {
"customer": {
"firstname": "Peter",
"lastname": "Smith"
},
"contract": {
"number": 1234560,
"name": "Gold Contract"
}
}
"output": {
"activityInstance" : aiOid,
"name" : letter.pdf,
}
}
The following example describes how to call the templating Service by using a UI Mashup application.
The model has a UI Mashup application configured as follows:
Figure: Templating Rest service
The UI mashup allows to enter a template name, its format as well as output response and location. Those parameters are used to invoke the REST service.
You find more details about UI Mashup applications here.
Once the model is deployed, we can execute the process and provide below values in the Templating Configuration UI.
Figure: Templating Rest service invocation
The template used is located in folder Root/artifacts/templates as shown below.
Figure: Template repository location
The response.pdf file has been generated and attached to the process instance
Figure: Templating output file