1. Home
  2. Administrators
  3. Document templates
  4. Macros
  5. Conditional (IF) macros in Word 365 templates

Conditional (IF) macros in Word 365 templates

This macro for Word 365 templates in Docuo allows you to establish a condition to determine whether or not the text fragment it contains will be included in the document.

Formula macros in Word templates are only available in Docuo Enterprise.

The definition of the formula is done in the Word document itself with the following syntax:

@DOCUO.IF{"condition",[reemplazo único]}

Word text fragment

@DOCUO.ENDIF{}

Where:

Condition: Filter that allows you to specify with T-SQL syntax the conditions that must be met in this conditional. Remember to use the category code at the beginning of the tags you use and, if you type the quotation marks from Word, you must press Ctrl+z after typing them so that Word does not replace them with a stylized quotation mark. We recommend writing the macro in a plain text editor and pasting it into Word afterwards.

Single replacement : Optional parameter. If TRUE, the replacement occurs only once (the formula will not be recalculated each time labels are replaced). By default it is FALSE so that each time labels are replaced the data is automatically updated.

In this example we use a conditional macro so that depending on the “Method of payment” of an invoice, a text fragment appears that contains the data to make the transfer:

Invoice number:< @Properties:Code>
Client:< @Customer:Name>
Amount:< @Data:Total>

@DOCUO.IF{"<@FAC:Data:Payment method>='Transfer'"}

CONTOSO BANK S.A.

IBAN: ES4202413226312852213980

Due date:< @Data:Expiration>

@DOCUO.ENDIF{}

As the UNIQUE REPLACEMENT parameter has been omitted, if the payment method changes, the condition will be evaluated again when labels are replaced from Docuo.

Conditional macros can be nested and contain other macros. Following the previous example, we could show the payment account in a different way depending on whether our client is international or not:

Invoice number:< @Properties:Code>
Client:< @Customer:Name>
Amount:< @Data:Total>

@DOCUO.IF{"<@FAC:Data:Payment method>='Transfer'"}

CONTOSO BANK S.A.

@DOCUO.IF{"<@FAC:Client:Country>='Spain'"}

IBAN: ES4202413226312852213980

Due date:< @Data:Expiration>

@DOCUO.ENDIF{}

@DOCUO.IF{"<@FAC:Client:Country><>'Spain'"}

SWIFT (BIC): CONT ES 1701 4202413226312852213980

Due date:< @Data:Expiration>

@DOCUO.ENDIF{}

@DOCUO.ENDIF{}

Conditional macros in Word templates allow you to create more advanced document templates without having to create different templates for different variations of your document.

Updated on 6 de November de 2023
Was this article helpful?

Related Articles