About this article
This article explains how to add smart fields to create a Word document with Dynamics.
- Adding smart fields to a document
- Adding a smart field step by step
- Add a 'Form responses' smart field to a template
- Add a 'User profile' smart field to a template
- Add a 'Text element' smart field to a template
- Add a 'Custom text binding' smart field to a template
- Add a 'Group' smart field to a template
- Add a 'Custom image binding' smart field to a template
Prerequisites
|
Adding smart fields to a document
When adding a smart field to a template in Word, Templafy automatically creates a content control for it. While this is fine in most situations, you need to use a placeholder text when you want to use custom formatting for the content control.
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. Note that even the font size has become smaller (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:
|
Adding a smart field step by step
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
Subject
field.
- In the template type a placeholder text e.g.
[Subject]
and select the text:
-
On the Template tab expand
Form responses
, select theSubject
form field and clickAdd to template
:
- If the Template tab already contains smart fields, then you first need to click
+ Add smart field
to displayForm responses
. - In the
Advanced
menu you can specify e.g. the visibility of the field (optional).
- If the Template tab already contains smart fields, then you first need to click
- 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 theDisplayName
user profile field and clickAdd to template
:
- If the Template tab already contains smart fields, then you first need to click
+ Add smart field
to displayUser profile
. - In the
Advanced
menu you can specify e.g. the visibility of the field (optional).
- If the Template tab already contains smart fields, then you first need to click
- 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 fieldAsset Id
type the Asset Id of the text element (in the example1234567890
), or use a binding to a data source column that contains the Asset Id, like{{UserProfile.Disclaimer.AssetId}}
and clickAdd to template
:
- If the Template tab already contains smart fields, then you first need to click
+ Add smart field
to displayText element
. - The option
Replace On Update
determines what happens when the user clicksUpdate 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 thenReplace On Update
needs to be enabled.
-
Text element is fixed part of template: if
- In the
Advanced
menu you can specify e.g. the visibility of the field (optional).
- If the Template tab already contains smart fields, then you first need to click
-
In the previous step note that the field
Placeholder
showsGenerate 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 clickEdit
to change the name (in the fieldQuestion title
) to e.g. 'Disclaimer' (optional):
- 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.
- On the Form tab you can select the Placeholder and click
-
The result looks like this:
- 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 the tags 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)
- 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:
|
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:
-
In the
Advanced
menu you can specify e.g. the visibility of the field (optional).
-
In the
- 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.
|
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
selectCustom visibility
.
-
In the field
Visibility expression
insert the binding{{IfElse(Contains(Lower(Form.Subject),"confidential"), VisibilityType.Visible, VisibilityType.Hidden)}}
. The result looks like this:
-
The
IfElse
function checks if the form fieldSubject
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:
- 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
- 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 etc.
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, but 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
.
- If the Template tab already contains smart fields, then you first need to click
+ Add smart field
to displayCustom image binding
.
- If the Template tab already contains smart fields, then you first need to click
-
The fields below are shown:
• 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 fieldInherit 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}}
.
-
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 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:
Related articles
Comments
Article is closed for comments.