Generate a file from a template

Document templates

Templates are used to automatically create documents. As a template you can use .rtf, .doc, .docx, .txt, .xls and .xlsx files.

In a template, you can use context variables of the String, Integer and Fraction types. To use context variables of other types, you need to convert them to String, Integer or Fraction first, using a script that will be executed in the business process before generating a document.


Template syntax

You can fill a template with any content and insert context variable. Use the following syntax: 

Text Text {$Context_Variable_Name} Text Text

Using blocks in templates

If you need to use a context variable of the Block type in a template, then the syntax of a block entry in the template should look like this: 

{for Item in {$Block}}
{$Item.Text1} {$Item.Text2} {$Item.Text3}

Block - the name of the context variable of the Block type.

Text1, Text2, Text3 - properties of the context variable of the block type. Block properties are added after the Item command separated by full stops.

When a file is generated from this template, the block properties will be written one after another.

The same syntax is used for templates in Excel files.

The for and end commands must be in the first column of the table, otherwise, the entered text will be displayed incorrectly.

Note that if you use these commands in a Word document with tables, the cycle start and end must be in the same cell as the cycle variable,

or outside the table.


Using conditions in templates

A condition starts with the {if <condition>} operator and ends with the {end} or {end if} operator.

<condition> - any condition, e.g. {$Applicants.Individual}=true

 General structure of a condition:

{if <condition>}
<Action if the condition is true>
<Action if the condition is false>

You can use nested conditions in templates: 

{if <condition>}text{end if}
{if <condition1>}text{if <condition2>}text{else}text{end if} text{end if}

Examples of using templates

Example 1.

You need to display the IECC of a company.


{if {$Contractor.TypeUid} = ’3325eab1-fe46-4900-a617-c6fb54ac24c0’}
Contractor's IECC:{$Contractor.IECC}
The contractor is not a company


First, check whether the contractor is a company. If the condition is true, display the contractor's IECC. If the condition is false, display "The contractor is not a company" in the template.

The Uid of an individual is 27e70dfe-2a76-4f1d-a99a-cdf31c62d618

In templates, the not equal to condition is used like this: <>

Example 2.

Display the legal address of a company in the following order: Country, City, Street, Building.

Template text: 

Legal address: {$Company.LegalAddress.Country.Name}, {$Company.LegalAddress.City}, {$Company.LegalAddress.Street} street, {$Company.LegalAddress.Building}.


Example 3.

Display in a template context variables with Yes values.

Template text:



The context variables Problem1, Problem2, Problem3, Problem4 have the Yes/No type. A file generated from the template will show only those issues, whose problems have the Yes value in the web part.


Example 4.

A more complex example is a contract template. This template can be used to instantly generate contracts.

Example 5. 

Take a look at the Consignment Invoice template:

This file is generated from the template:


Example 6.

If you need to change the color of a cell depending on a condition, then add a condition to the template, specifying what color and style to use.

Condition example:

{if {$Value} = 123} // Set the condition according to which the cell color will be changed. If the condition is true, the text color and style will be changed according to the next line. 
{$Value} // In this line, the text style and cell color is set. Change the cell color to the required and it will be used when generating a document. 
{else} // Next condition 
{$Value} // In a similar way, set the cell color and text style. 
{end} // End of condition

The template uses the Value context variable. According to the condition, if the Value = 123, then the variable will be displayed in red font on a yellow background, otherwise, the cell will be blue and the font will be white.


Example 7.

Compare two variables.

Template text:

{if {$Date1}>{$Date2}}
{$Date1} greater than {$Date2}
{$Date1} not greater than {$Date2}


Example 8.

Check for being null.

Template text:

{if {$NullableDate}=null}
date is not specified
date - {$NullableDate}