﻿# Special functions of template syntax

> [HTML Version](another-template-syntax-functions.html)

The article describes the rules of using additional functions of [template syntax](360026936731.md):

- [Barcode()](#barcode) to display the contents of a variable in a document as a barcode.

- [JobPosition()](#job-position) to add the user's position.

- [PasteImage()](#pasteimage) to insert an image in place of the variable.

- [HYPERLINK()](#hyperlink) to convert the table content into a hyperlink.

- [ExtText()](#exttext) to create a custom function for advanced features of working with the document template.

## Barcode() function

To encode a **String** type field in an app and add it to a document as a barcode, use the \[OBJECT\] function. For instance, you can use it to generate a barcode for a contract’s registration number or another unique number assigned to a document. Later you can use this barcode to match the hard copy of a document with its digital version. 

You can use barcode scanning software in BRIX if you configure an appropriate integration module. Read more about it in [Standard modules](360024498352.md) and [Introduction to Web API](https://api.brix365.com/en/public-api/guides/IntroWebAPI/).

The system allows you to generate barcodes for **Word** and **Excel** files.

Syntax: \[OBJECT\]. Specifying the height is optional.

- **\[1\]**: the content of the string depends on the format specified in the second parameter.

- **\[2\]**: available barcode formats and requirements to the string:

	- **QR Code**:** **Any string. Resolution up to 300 DPI is supported.

	- **EAN-8**: A string consisting either of 7 digits or of 8 digits (seven digits and a check digit).

	- **EAN-13**: A string consisting either of 12 digits or of 13 digits (twelve digits and a check digit).  
  
You can also add **EAN** format without specifying the type. In this case, the type of the generated barcode will depend on the number of digits in the sent string.

- **\[3\]**: barcode height in pixels is an optional parameter. For correct recognition, the height is specified based on the number of characters used.

If the template uses the same string to generate a QR code twice, but specifies a different size, a QR code of the same size will be generated in both cases.

````
начало внимание

````
If no checksum was specified when using **EAN** formats, it will be added automatically. For correct operation, the barcode scanner must be configured to work with these formats.

````
конец внимание

````
It is recommended to use the **QR Code** format, as it can be applied to a greater variety of data, while the **EAN** formats are limited.

For example, there is a variable \[OBJECT\], and its value is **5901234123457**. From this string, a QR code or an EAN-13 can be generated.

````
начало примера

````
Examples

1. \[OBJECT\].

2. \[OBJECT\].

````
конец примера

````
For an EAN-8, the string can only include 8 digits: \[OBJECT\].

## JobPosition() function

This function is used to get a user’s job position.

Syntax: \[OBJECT\]

You can use the \[OBJECT\] variable to get only the first job position or the \[OBJECT\] variable to get all job positions of a user.

````
начало примера

````
Example

\[OBJECT\] —> The function will pass all job positions of the user specified as the app item’s **Author**.

````
конец примера

````


## PasteImage() function

To paste an image from a context variable of the [Image](360009707032.md#image) or [Files](360009707032.md#file_type) type into a document template, use the \[OBJECT\] function.

Syntax: \[OBJECT\]

````
Начало примера

````
Examples

1. \[OBJECT\]. The image will be inserted with the original width and height values into the variable of the **Image** type.

2. \[OBJECT\]. The image will be inserted with the original width and height values into the variable of the **Files** type.

3. \[OBJECT\]. The image will be displayed with a width of 200 pixels in the variable of the **Image** type. The height value will change, the original proportions will be preserved.

4. \[OBJECT\]. In the **Files** type field, the function scales the image to a strictly specified size.

5. \[OBJECT\]. The image from the variable will be displayed with a height of 400 pixels. The width value will be scaled, the original proportions will be preserved.

6. \[OBJECT\]. In the **Files** type field, the function will crop the image to the specified size without taking into account the original proportions.

````
Конец примера

````
By default, the `PasteImage()` function allows you to insert a single image or file into a document. To display multiple objects, use the function within a [for loop](360027003711.md#for).

````
Начало примера

````
Example

1. You want to display a list of images in a document. The list is passed to the `image1` template variable of the **Image (Several) **type.

2. The for loop allows you to repeatedly apply the `PasteImage()` function to sequentially insert all the images in the list into the document.

For correct operation, a temporary `image2` variable of the **Image (one) **type is added to the template as a parameter. Each image is placed into this variable in turn and then passed to the `image1` variable.

````
\{for image in \{\$image1\}\}  
\{PasteImage(\{\$image2\}, 400, 200)\}  
\{end\}

````
After the loop completes, the list of images will be displayed in the document.

````
Конец примера

## ````
HYPERLINK() function for tables

When generating a template in a **.xls** and **.xlsx** file, you can use the  \[OBJECT\] function. This is a standard Excel function that allows you to convert a given value into a hyperlink.

You can use variables of type [String](360009707032.md) from the app context as arguments, as well as set values manually. For the function to work correctly, the full URL of the link is specified.  

Syntax:

````
начало примера

1. ````
\[OBJECT\]. A text hyperlink is displayed leading to the specified website.

2. \[OBJECT\]. An URL hyperlink is displayed. 

Examples

3. \[OBJECT\].  The website address is specified as a string in the app item, the hyperlink is specified manually.

4. \[OBJECT\]. The website address is specified manually, the hyperlink is formed using the app item field value. 

````
конец примера

## ````
ExtText() function

In case system functions are not enough to customize a template, you can create a custom \[OBJECT\] function. The function allows you to call  [API methods](extention-api.md) described in custom modules and apply them to the generated template.

Syntax: \[OBJECT\]: 

- **Module id**. Characters from the module URL coming after **/ext\_**. For example, if the module URL is **mycompany.brix365.com/admin/extensions/ext\_12ab-1212**, then **12ab-1212 **should be inserted into the function.

- **Method address**. The value of the **Address** field from the table located on the **API Methods** tab in the [settings of the module](extention-api.md). 

- **Additional parameters**. An optional parameter that is passed to the specified method, for example, an app property. In the request body the additional parameters are displayed as **p1**, **p2**, etc. The are passed in the \[OBJECT\] function separated with a comma after the mandatory parameters. Please note, the values will be assigned to the parameters in the order in which they are declared in the method request body.

````
Начало примера

````
Example

You can apply the \[OBJECT\] function in naming app items. To do that:

1. Create a module and set up an API method that will be used for generating app item names.

2. Create a [name template](360007679591.md#name_template) by using the \[OBJECT\] function.

For example:

\[OBJECT\]

3. The function will trigger the method that will process the passed parameters. After the conditions specified in the method are executed, the result can be used as an app item name.

Example of an API method script for creating app item names

````
async function name(req: HttpApiRequest): Promise<HttpResponse | void> \{  
     const resp = new HttpResponse();  
     let result: string = "";  
     let bodystr: string = req\!.body\!.toString();  
       
     JSON.parse(bodystr, function (k, v) \{ // k and v - key and value  
  
         if (k \!= '') \{ // you can set your conditions  
             result += "\_key"+k  
             result += "\_value"+v  
         \}  
  
   \});  
  
     resp  
        .status(200)  
        .content(result)  
        .set('Content-Type', 'text/html')  
  
    return resp  
\}
````

Конец примера

````
When using complex custom functions, you can change their processing mode to speed up the generation of template documents. All variables and functions will be processed in parallel instead of sequentially one after another.

For this purpose, you can enable the \[OBJECT\] flag for** **BRIX On-premises in the \[OBJECT\] configuration file. For more details, see [Modify BRIX parameters](change-settings-enterprise.md#enable-feature-flag-enterpeise).

After enabling the flag, you can set the number of parallel processing threads using [additional parameters](change-settings-enterprise.md).