DocumentsCorePack templates can utilize Microsoft Word’s many formatting tools and options. Word’s own field codes are no exception. In tandem with the Template Designer’s fields, such fields can add another dynamic layer to your documents.
This article describes how to use common field codes in combination with Dynamics 365 data.
Note: Delimiters for Word formulas and methods will vary based on culture. For English-based systems, the delimiter character is the comma (“,”), whereas for German-based systems, the delimiter character is the semicolon (“;”). Please keep this in mind when constructing your own formulas. The examples in this article are all based on an English system.
Table of Contents
- The “IF” field
- The “DocProperty” field
- The “= (Formula)” field
- The “Set” and “Ref” fields
- The “SEQ” field
The “IF” field
The IF field inserts a specified value based on comparing two values allowing content to be conditionally added to documents. The field code has the following syntax:
{ IF Expression1 Operator Expression2 TrueText FalseText}
Fields from Dataverse can be inserted in place of the expressions or the true/false text to produce a condition based on the corresponding values.
For a detailed description and example, please see this article.
The “DocProperty” field
The DocProperty field will insert a specified value from the document’s Properties. The field code has the following syntax:
{ DOCPROPERTY “Name” }
In combination with dynamic document properties, Dataverse values can be written to the properties of a generated document, allowing the DocProperty field to insert the dynamic value into the document itself.
Example:
We can set the Company property of the document to be the name of an account’s record by adding a text-based dynamic document property. This is shown below:
Then, after adding the DocProperty field code for the Company property in the document…
…the dynamic value will be displayed upon merging the template:
The “= (Formula)” field
The Formula field performs a calculation based on a given mathematical formula. Values from Dataverse can be inserted via the Template Designer within Formula fields to generate a dynamic result.
Example:
We can calculate and apply tax to the total amount of a quote by using a formula field. After adding the field and applying the necessary formatting, we can add our Dataverse fields along with a fixed value for our tax.
The corresponding values will appear in our formula after generating the document. The formula will calculate the result based upon these values.
Note: DocumentsCorePack’s calculated fields can achieve similar results.
The “Set” and “Ref” fields
The Set and Ref fields assign and insert information in the document based on a given bookmark, respectively. More specifically, the Set field “sets” data to a bookmark, while the Ref field “references” the information from the bookmark once placed in the document.
Dataverse fields can be used in combination with Set and Ref fields. By inserting them into the former, they can be later used by the latter.
Example:
When creating a thank you message that includes the price and number of licenses purchased, we can set our fields from Dynamics 365 using the Set field in order to reference them later.
After merging the template, the Dataverse fields will pull the data from our record.
The result will display the corresponding information in our thank you message.
(For another example that uses the Set field, please see our article on ordinals)
The “SEQ” field
The SEQ field numbers items in a document sequentially. If used in tandem with a dynamic table, it can be used to number the table’s line items.
Example:
If we create a simple invoice table, we can position the fields in such a way where the Seq field can be placed on the right hand side.
When the template is merged, the resulting document will display the item numbers in sequence.
That’s it! We appreciate your feedback! Please share your thoughts by sending an email to support@mscrm-addons.com.