This article explains how to add smart fields to create a Word document with Dynamics.
Prerequisites
|
Adding smart fields to a document
When adding a smart field to a template in Word, Templafy automatically creates a content control including a placeholder text. When you want to use custom formatting for the content control, you need to select text as a placeholder text before adding the smart field.
For example you have a 'Subject' field and add it to the template by clicking Add to template:
When no placeholder text is used the Display name is shown in grey text (1).
If you then change the formatting of the content control to e.g. bold+italic (2), then the result (when a document is created) is that 'hello world' is not bold+italic (3):
If a placeholder text like [Subject] is used (1) and then the formatting of the content control is changed to bold+italic (2), then this time the result is that 'hello world' is shown in bold+italic text (in the correct font size) as expected:
ImportantIt is recommended to always use a placeholder text. |
Add a 'Form responses' smart field to a template
Follow the steps below to add a 'Form responses' smart field to your template. In the example a 'Subject' field is used.
- On the Form tab create a text field Subject.
- In the template type a placeholder text e.g. [Subject] and select it:
-
On the Template tab expand Form responses and select the Subject form field and click Add to template:
Note
- If the Template tab already contains smart fields, then you first need to click + Add smart fields to display Form responses.
- In the Advanced menu of the smart field you can specify e.g. the visibility of the field (optional).
- The result looks like this:
- Save the template.
-
When a user creates a document the Subject form field is shown in the Composer and the value is inserted into the content control. The result looks like this:
Add a 'User profile' smart field to a template
Follow the steps below to add a 'User profile' smart field to your template. In the example the DisplayName field is used.
- In the template type a placeholder text e.g. [Author] and select the text:
- On the Template tab expand User profile, select the DisplayName user profile field and click Add to template:
Note
- If the Template tab already contains smart fields, then you first need to click + Add smart fields to display User profile.
- In the Advanced menu of the smart field you can specify e.g. the visibility of the field (optional).
- The result looks like this:
- Save the template.
-
When a user creates a document a user profile field is not shown in the Composer but the value is directly inserted into the content control. The result looks like this:
Add a 'Text element' smart field to a template
Follow the steps below to add a 'Text element' smart field to your template. In the example the Disclaimer text element is used.
- In the template type a placeholder text e.g. [Disclaimer] and select the text.
-
On the Template tab select Text element. In the field Asset Id type the Asset ID of the text element (in the example 1234567890), or use a binding to a data source column that contains the Asset ID, like
{{UserProfile.Disclaimer.AssetId}}
and click Add to template.
Note
- If the Template tab already contains smart fields, then you first need to click + Add smart fields to display Text element.
- The option Replace On Update determines what happens when the user clicks Update document:
- Text element is fixed part of template: if Replace On Update is disabled then values of form fields still will be updated, but if the content of the text element has changed (e.g. in the Admin Center the original version is replace by a new version) this will not be updated.
- Text element is inserted via dropdown: if Replace On Update is disabled then the dropdown will not be shown anymore. For example if the user can choose to Yes/No insert a text element and chooses 'No', then it's not possible anymore (after the document is created) to change it to 'Yes'. If you want the user to be able to change the answer then Replace On Update needs to be enabled.
- In the Advanced menu of the smart field you can specify e.g. the visibility of the field (optional).
-
In the previous step note that the field Placeholder shows Generate new by default. This means a new placeholder will be created ('Placeholder 1', 'Placeholder 2' etc.). If you select the placeholder on the Form tab, you can click Edit to change the name of the placeholder:
Tip
- On the Form tab you can select the Placeholder and click Edit to change the default name 'Placeholder X' to e.g. 'Disclaimer'. This is not required, but it's easier to use a descriptive name if a template has many text elements.
- You can change the position of the placeholder on the response form. If a text element contains form fields, this determines where the questions will be shown on the response form.
-
The result looks like this:
Important
- As you can see in the image above, the 'Disclaimer' text element is used in it's own paragraph. The paragraph does not contain any other text.
- If you enable Design Mode in the Word ribbon (tab Developer) the tags of content controls are shown:
- A correctly used text element content control can be recognized by two (start and end) textElement tags (marked green).
This is the case when the text element is used in it's own paragraph or table cell. -
An incorrectly used text element content control will only have one (start) textElement tag (marked red). This means it's an inline text element which is not supported by Templafy.
Deleting the sentence will not solve this: the end tag is deleted permanently.
The solution is to delete the current content control and create a new one.
- A correctly used text element content control can be recognized by two (start and end) textElement tags (marked green).
- Save the template.
- When a user creates a document the result looks like this:
If a text element is inserted via a dropdown then the user can edit or delete the text after the document is created. If you don't want to allow that then you can enable these options in the properties of the content control:
ImportantIf a user inserts a text element manually (from the library) it will always be inserted as plain text. |
Add a 'Custom text binding' smart field to a template
In situations where you cannot use a User profile or Form responses smart field you have the option to create a Custom text binding smart field. You can use a custom text binding for example if you want to show the current date in your document as shown below.
- In the template type a placeholder text e.g. [Date] and select the text.
-
In the task pane select Custom text binding and insert a binding like
{{FormatDateTime(Now(),"dd/MM/yyyy")}}
. The result looks like this:
Note
In the Avanced menu you can specify e.g. the visibility of the field (optional).
- Click Save to create the binding.
- The result looks like this:
- Save the template.
- When a user creates a document the result looks like this:
Add a 'Group' smart field to a template
With form fields, user profile fields and text element fields you can use the option Custom visibility in the Visibility field to show, hide or even delete the field, based on specific conditions.
You can also use the Group smart field to achieve the same result.
ImportantIn general the Group smart field is used to show, hide or delete a combination of plain text and fields. If you only want to show, hide or delete an individual form field, user profile field or text element field, then use the Visibility setting of that specific field. |
In the example below the 'Disclaimer' text element from the example above is used. Follow the steps below to hide the disclaimer text when the 'Subject' does not contain the text 'confidential'.
- In the template select the [Disclaimer] content control.
-
In the field Visibility select Custom visibility.
-
In the field Visibility expression insert the binding
{{IfElse(Contains(Lower(Form.Subject),"confidential"), VisibilityType.Visible, VisibilityType.Hidden)}}
. The result looks like this:
Note
-
The
IfElse
function checks if the form field Subject contains the text 'confidential'. If it does then the disclaimer text will be visible, else it will be hidden. Because theLower
function is also used, it doesn't matter if a user types e.g. 'confidential', 'CONFIDENTIAL' or 'ConFiDenTiaL'. - In the Advanced menu you can set to allow updates (this is enabled by default).
-
The
- Click Add to template to create the group.
-
The result looks like this:
Note
- The 'Disclaimer' text element has now become part of the group.
- In the task pane fields that are part of a group are indented.
- Save the template.
-
When a user creates a document the result looks like this:
Subject Result 'Hello world' Disclaimer text is hidden. 'Confidential Disclaimer text is shown. 'Info about confidentiality of documents' Disclaimer text is shown. Note
- The Group smart field can also be used to show, hide or delete multiple text elements, form fields or user profile fields at once, by selecting all fields and place a group around them.
- The Group smart field can also be used to show, hide or delete plain text, images, tables etcetera.
Add a 'Custom image binding' smart field to a template
If you want to add a logo to the header of a Word document then in general it's recommended to use the Image Header document property. If you want to add an image to the body of the document you can use the Custom image binding smart field, following the steps below.
In the example below the 'ImageFiles' data source is used:
- In the template place the cursor at the location where you want to show the image (don't select any text!).
-
In the task pane select Custom image binding.
Note
- If the Template tab already contains smart fields, then you first need to click + Add smart field to display Custom image binding.
-
The fields below are shown:
Field Description Display name The name of the field. Image Binding to the image. The example above contains a binding to a specific image using the DataSources[] function (
{{DataSources.ImageFiles["Pear"].Image}}
), but a binding like{{UserProfile.Office.Logo}}
can also be used.Inherit Dimensions This defines if the image will inherit the dimensions of the placeholder field (see image in step 4), which by default is 2.64 x 2.64 cm. This field has four options:
- InheritNone: The width and height of the original image are used.
- InheritWidth: The image will inherit the width of the placeholder field (the height will be set accordingly so the aspect ratio is maintained).
- InheritHeight: The image will inherit the height of the placeholder field (the width will be set accordingly so the aspect ratio is maintained).
-
Custom inheritDimensions: If this option is selected then the additional field
Inherit Dimensions expression
is shown, where you can create an expression that defines which option should be used depending on a specific value. For example:
{{IfElse(Equals(Form.Dimension.Name, "Width"), InheritDimensions.InheritWidth, IfElse(Equals(Form.Dimension, "Height"), InheritDimensions.InheritHeight, InheritDimensions.InheritNone))}}
Width The width of the image in cm. If you leave the Height field empty, then the image will keep it's aspect ratio. You can also use a binding like
{{UserProfile.Office.LogoWidth}}
.Height The height of the image in cm. If you leave the Width field empty, then the image will keep it's aspect ratio. You can also use a binding like
{{UserProfile.Office.LogoHeight}}
.Important
-
Click Add to template. The image placeholder field is inserted at the location of the cursor:
- Optional: resize the placeholder field. Note that this has no effect if in the Inherit Dimensions field the option 'InheritNone' has been selected.
Show the image behind text
The wrapping style of the image placeholder field will automatically be set to 'In line with text'. The other options shown in the image below are not supported:
However if you want to use any of the other wrapping styles (for example to show the image behind text), you can do this by creating a shape or a text box, set the wrapping style option for the shape/text box and then add the image content control inside it:
- On the Insert tab of the Word ribbon select a (rectangle) shape or draw a text box at the position where you want to show the image:
- Select the shape or text box and set the wrapping style to e.g. 'Behind Text'.
- Insert the Custom image binding smart field inside the shape/text box.
- Set the colors of the shape/text box to 'No Fill' and 'No Outline':
- Save the template.
- When a user creates a document the result looks like this:
Comments
Article is closed for comments.