How to write a document template with the legacy syntax

This section provides a list of functions to format variables into a document template in Microsoft Word format. To use the functions described below, edit the merge field behind the variable and rename the merge field with the function itself. Please note that you need the Document Generation feature activated to be able to use this.

Text format functions

$textUtil.capitalize($firstname): Capitalizes the first letter of the text inserted in the variable.

$textUtil.uppercase($firstname): Changes the content of the variable to uppercase.

$textUtil.lowercase($lastname): Changes the content of the variable to lowercase.

Number format functions

$numberUtil.format($number): Formats a number based on the language of the document template.

$numberUtil.format(“#0.00”, $mynumber): Formats a number in decimal with two digits after the decimal separator.

Example

You have created a document template with the language “English (United States)”, the employee’s salary has the following default format: $numberUtil.format($number)==> 2,500.53

Mathematical functions

You can perform basic calculation operations (addition, subtraction, multiplication and division) in a document template. This feature is only available via API.

#set($result = $number1 + $number2): Adds up two numbers and enters the sum into the $result variable.

#set($result = $number1 * $number2): Multiplies two numbers and enters the product into the $result variable.

#set($result = $number1 - $number2): Subtracts two numbers and enters the difference into the $result variable.

#set($result = $number1 / $number2): Divides two numbers and enter the quotients into the $result variable.

$numberUtil.div(2,$result,$b): Divides $result by $b and displays the result in decimal format.

Example

You want to automatically calculate an employee’s total salary based on their base salary and bonus salary.

To display the result, do not forget to display the $salary_total variable:

#set($total_salary = $base_salary + $bonus_salary) $total_salary

Note

you can format the result in the supported formats (see paragraph above). Using the previous example, here is how to do this if you want to format the total salary in French format: #set($total_salary = $base_salary + $bonus_salary) $numberUtil.format($total_salary, "fr", "fr")

Conditional functions

«#if($condition)» Yes «#end»: Displays a text if a condition is fulfilled.

«#if($condition)» Yes «#else» No «#end»: Displays one of the two texts (Yes or No) if a condition is fulfilled.

«#if($condition1)» Yes «#elseif($condition2)» No «#elseif($condition3)» Maybe «#else» Etc «#end»: Displays one of the texts (Yes/No/Maybe/Etc) if one condition is fulfilled.

Note

The conditions can be extended using the following operators:
AND: &&
OR: ||
DIFFERENT FROM: !

Examples

You want to display an employee’s middle name if necessary: «#if($middle_name)» «$middle_name» «#end»

You want to display Mister if the employee is a man, Madam if not: «#if ($custom_fields_gender == "man")» Mister «#else» Madam «#end»

You want to display indefinite duration if the contract is a permanent contract, fixed duration if the contract is a fixed-term contract, duration to be defined in other cases: «#if($contract_type == "permanent contract")» indefinite duration «#elseif($contract_type == "fixed-term contract")» fixed duration «#else» duration to be defined «#end»

Note

You need to include #if, #else and #end in separate merge fields as shown below so that the variables are detected. Also, the conditions are case sensitive, for example in this conditional function #if ($custom_fields_gender == "male"), if you insert Man instead of man, the result in the #else section is displayed.

Moreover, he values you wish to apply must be lower case even if the information is capitalized in the profile used. For example, if in the employee profile the value of the custom field gender is MALE in uppercase, your condition must be written as follows: #if ($custom_fields_gender == "male")

../../_images/custom_field_condition.png

Date format functions

«$dateUtil.formatUS($dateUtil.currentDate())»: Generates the current date in US format MM-dd-yyyy.

«$dateUtil.formatEU($dateUtil.currentDate())»: Generates the current date in EU format dd-MM-yyyy.

«$dateUtil.formatISO($dateUtil.currentDate())»: Generates the current date in ISO format yyyy-MM-dd.

«$dateUtil.format("dd-MM-yyyy", $starting_date)»: Formats a date in a specified format (dd-MM-yyyy). Other examples of formats that can be used are: MM-dd-yyyy, yyyy/dd/dd/MM, dd/MM/yyyy, yyyy. MM. dd HH: mm: ss.

«$dateUtil.format("full_date", $starting_date)»: Displays a date in one of the predefined formats listed below.

Style

US Format

French Format

default_date

Jun 30, 2021

30 juin 2021

short_date

6/30/18

30/06/18

medium_date

Jun 30, 2021

30 juin 2021

long_date

June 30, 2021

30 juin 2021

full_date

Wednesday, June 30, 2021

mercredi 30 juin 2021

Examples

You want to format a date in long_date format. «$dateUtil.format("long_date", $date)» displays January 8, 2021

You want to format a date in “dd/MM/yyyy” format. «$dateUtil.format("dd/MM/yyyy", $starting_date)» displays 14/04/2021

You want to format the current date in “full_date” format. «$dateUtil.format(\"full_date\", $dateUtil.currentDate())» displays Wednesday, March 3rd, 2021

Note

The input format of the dates you want to display must be in ISO format yyyy-MM-dd.

Additional information

By default, a mergefield composed of a variable or function that contains more than 42 characters is truncated by Microsoft Word. This is only a display rule, the content of the mergefield is well preserved.

Example:

../../_images/truncated_merge_field.png

Here is a ready-to-use block to handle correctly spaces, for the following common use case: “I want the middle name of an employee to be displayed only if defined with correct spacing between the firstname, middle name and lastname”:

TOOLBOX-firstname-middlename-lastname-space management.docx