Articles in this section

How to create Smart fields in Word

About this article

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 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:

wd_subject.png

 

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):

wd_contentnoplaceholder.png

 

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:

wd_contentplaceholder.png

 

 
  • It is recommended to always use a placeholder text.

 

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.

  1. On the Form tab create a Subject field.

  2. In the template type a placeholder text e.g. [Subject] and select the text:

    wd_placeholder.png

  3. On the Template tab expand Form responses, select the Subject form field and click Add to template:

    wd_formsubject.png

     
    • If the Template tab already contains smart fields, then you first need to click+ Add smart field to display Form responses.
    • In the Advanced menu you can specify e.g. the visibility of the field (optional).

     

  4. The result looks like this:

    wd_subjectplaceholderbinding.png

  5. Save the template.

  6. 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:

    wd_subjectdocument.png

 

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.

  1. In the template type a placeholder text e.g. [Author] and select the text:

    wd_placeholderauthor.png

  2. On the Template tab expand User profile, select the DisplayName user profile field and click Add to template:

    wd_userprofiledisplayname.png

     
    • If the Template tab already contains smart fields, then you first need to click+ Add smart field to display User profile.
    • In the Advanced menu you can specify e.g. the visibility of the field (optional).

     

  3. The result looks like this:

    wd_authorplaceholderbinding.png

  4. Save the template.

  5. 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:

    wd_authordocument.png

 

 

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.

  1. In the template type a placeholder text e.g. [Disclaimer] and select the text.

  2. 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:

    wd_disclaimertextelement.png
     

     
    • If the Template tab already contains smart fields, then you first need to click+ Add smart field to display Text element.
    • The option Replace On Updatedetermines 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 you can specify e.g. the visibility of the field (optional).

     

  3. 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 (in the field Question title) to e.g. 'Disclaimer' (optional):

    wd_placeholderedit.png

     
    • 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.

     

  4. The result looks like this:

    wd_disclaimerplaceholderbinding.png

     

     
    • 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:

      wd_textelementdesignmode.png
      • 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.

     

  5. Save the template.

  6. When a user creates a document the result looks like this:

    wd_disclaimerdocument.png

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:

wd_contentcontrolproperties.png

 

 
  • If 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.

  1. In the template type a placeholder text e.g. [Date] and select the text.

  2. In the task pane select Custom text binding and insert a binding like {{FormatDateTime(Now(),"dd/MM/yyyy")}}. The result looks like this:

    wd_customtextbinding.png


     
    • In the Advanced menu you can specify e.g. the visibility of the field (optional).
     
  3. Click Save to create the binding.

  4. The result looks like this:

    wd_dateplaceholderbinding.png

  5. Save the template.

  6. When a user creates a document the result looks like this:

    wd_datedocument.png

 

 

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 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'.

    1. In the template select the [Disclaimer] content control.

    2. In the field Visibility select Custom visibility.

    3. In the field Visibility expression insert the binding {{IfElse(Contains(Lower(Form.Subject),"confidential"), VisibilityType.Visible, VisibilityType.Hidden)}}. The result looks like this:

      wd_group.png


       
      • 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 the Lower 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).


    4. Click Add to template to create the group.

    5. The result looks like this:

      wd_groupcontentcontrol.png

       
      • The 'Disclaimer' text element has now become part of the group.
      • In the task pane fields that are part of a group are indented.
       
    6. Save the template.

    7. 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:

wd_imagefiles.png

  1. In the template place the cursor at the location where you want to show the image (don't select any text!).

  2. 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 display Custom image binding.

     

  3. 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 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))}}

     
    • Use the value(s) InheritDimensions.InheritWidth and/or InheritDimensions.InheritHeight and/or InheritDimensions.InheritNone in the expression.
    • The Switch() function is not supported in combination with the values above. Use the IfElse() function instead.

    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}}.

  4. Click Add to template. The image placeholder field is inserted at the location of the cursor:

    wd_imagefield.png

  5. 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:

wd_textwrapping.png

 

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:

  1. On the Insert tab select a (rectangle) shape or draw a text box at the position where you want to show the image:

    wd_shapetextbox.png

  2. Select the shape or text box and set the wrapping style to e.g. 'Behind Text'.

  3. Insert the Custom image binding smart field inside the shape/text box.

  4. Set the colors of the shape/text box to 'No Fill' and 'No Outline':

    wd_shapebehindtext.png

  5. Save the template.

  6. When a user creates a document the result looks like this:

    wd_imagebehindtext.png

 

Related articles

 

 

 

 

dynamics functions smart fields
Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Article is closed for comments.