Skip to main content

3.9. Generate Documents from Templates

The system allows generating documents from templates by inserting values from document attributes into a predefined template.

You must prepare a template in .doc / .docx format and specify the attribute codes that will be retrieved from the document. Template creation is described in section 2.3.6. Document Templates.

The template can include:

  • native document attributes — specify the attribute code directly. Examples: {subject} — short description, {docTypeID.caption} — document type name

  • document role attributes — specify the role code after {mi_participants.xxx}. Examples: {mi_participants.author} — the Author role, {mi_participants.responsible} — the Responsible Performer role

  • custom document attributes — specify the attribute code after {attrValues.xxx}. Examples: {attrValues.ms03} — value from the ms03 attribute, {attrValues.ms08.caption} — value from the system dictionary reference attribute

  • values from custom Switch attributes — specified in the same way as other custom attributes using {attrValues.xxx}. However, for Switch attributes, you can display different text in the document depending on the switch value. Examples:

    Depending on the value of the toogle switch attribute, the document displays either Approved if the switch is enabled, or Not approved if the switch is disabled.

    {^attrValues.toogle}Not approved{/attrValues.toogle}
    {#attrValues.toogle}Approved{/attrValues.toogle}

    Depending on the value of the ms15 switch attribute, the document displays either the value of the ms02 attribute if the switch is enabled, or the value of the ms01 attribute if the switch is disabled.

    {^attrValues.ms15}{attrValues.ms01}{/attrValues.ms15}
    {#attrValues.ms15}{attrValues.ms02}{/attrValues.ms15}
  • values from table attributes — specify the table attribute code and the attribute codes located within the table. Example:

    The values of the ms01, ms02, and ms03 attributes will be retrieved from the ms16 table attribute.

    {#attrValues.ms16}
    {attrValues.ms01},
    {attrValues.ms02},
    {attrValues.ms03}
    {/attrValues.ms16}

    Retrieve values as a table:

  • custom Formatted Text attributes — available when the paid HTML module is installed. Using the {~attrValues.ms19} code in the template, the value of the Formatted Text attribute with the ms19 code is inserted into the document as part of the text without line breaks. Using the {~~attrValues.ms19} code, the value is inserted as an entire paragraph with support for multiline formatting and styles.

If the paid HTML module is not installed, the attribute value is inserted into the document as plain text without formatting. In this case, use the following syntax in the template: {attrValues.ms19}.

After the document template is created, assign it to a file attribute on the document form or table attribute form. To do this, in the form designer, select a file attribute (Document Image, Document Attachments, File, or File Collection) and configure a document template for it.

For the Document Attachments and File Collection attributes, you can configure multiple templates.

You can generate a document from a template in the following ways:

  • Using the action button in a file attribute — the button remains disabled until a document template is assigned to the file attribute.

  • Using a script — requires a template to be assigned to the file attribute.

  • Using a handler — to create a handler, open the document type settings, go to the Events tab, and click Add Handler. Then select the event that will trigger the handler, for example, an action execution event, and choose the Generate Document from Template handler.

    In the handler settings, you can:

    • select the document template source — a template from the template dictionary, a standard attribute, or a custom attribute. If attributes are selected as the source, a document template file must be added to the selected attribute before the handler is executed
    • select the attribute where the generated document will be saved — either a standard or custom attribute available on the document form
    • configure save conditions — define what happens if the target attribute already contains a signed file
    • select a language — depending on the selected language, the date format and reference attribute values will change
    • configure a time zone — depending on the selected time zone, date values in the generated document will be adjusted accordingly