How to Update an Existing Word Document

Our goal in this tutorial is to show how to modify data and/or template design of a Word document with DSP (Data Source Provider) class or query, assigned to a Docentric Template Library.

Let’s assume that we’ve already created a new Word document ‘Sales Order Preview’, within the Sales Template Library, for the Primary table SalesTable. This document represents a printed sales order and can be generated for any sales order from the Sales orders list page. Please see the previous tutorials to learn how to create such a document in the first place:

  • On how to create the ‘Sales Order Preview’ document with a DSP class you can learn here.
  • On how to create the ‘Sales Order Preview’ document with a DSP query you can learn here.

Suppose that we forgot to print some customer information on the document. First we need to include the missing data in the document data source and afterwards modify the template itself. More precisely, we have to take the following steps:

  • Update the DSP class and regenerate the changed Data Source Package file.
  • Modify the document template using the updated Data Source Package.
  • Synchronize the template, if needed. In that case we must activate it again.
  • Generate the document from the template on the Sales Orders list page in a standard way.

1. Update the DSP class or query

Suppose that we need to add some customer info to the data source of the existing document ‘Sales Order Preview’ assigned to the Sales Docentric Template Library. If you are not sure what the name of your DSP class or query is, open the Docentric document types form. The form can be opened from the Company/System administration/Area page/Setup/Docentric AX menu.

Open the Docentric document types form and locate the Sales Docentric Template Library document type.

Click the Properties button and check the type and the name of your DSP class/query.

Let’s say that we want to include Customer Name and Address in the document data source. To achieve this we have to modify implementation of the generateXmlDataSource() method of our SalesTableDsProvider DSP class.

In the case of a DSP query, we have to modify the definition of the query and/or to add new display methods on tables (which are data sources of the query).

After the DSP class or query has been updated we have to regenerate Docentric Data Source Package (DDSP file) that will be used later when modifying the document template.

2. Regenerate Data Source Package

Open the Docentric document types form and locate the Sales Docentric Template Library document type. Select the SalesOrderPreview template and click the Refresh DS button.

The Generate data source form is open. Before we regenerate the updated data source we can select another SalesTable record to be used as the template sample data, alter the template language, etc.

Click the Generate data source button. The updated Data Source Package (DDSP file) with two new fields (CustomerName and CustomerAddress) has been generated.

3. Modify the template

The next step is to make newly added fields CustomerName and CustomerAddress visible in the ‘Sales Order Preview’ document template. However, the template data source will not be updated automatically. We need to this manually.
Open the Docentric document types form and locate the Sales Docentric Template Library document type. Select the SalesOrderPreview template and click the Design button. We can use the same Design button in case of template storage on SharePoint as well. Alternatively, you can open the template directly from its location.

Open the template and navigate to the Docentric AX ribbon. Click the Load Data Source button and select the updated Docentric Data Source Package (DDSP file).

You can see that new data related to Customer (two new fields: CustomerName and CustomerAddress) show up in the Data Source pane.

Add new Docentric Field tagging elements and bind them to the Customer Name and Address as shown on the picture below. Format them using built-in Word’s formatting and styles.

Preview the changed document by clicking the Preview button on the Docentric AX ribbon.

In case of template storage on SharePoint, we need to regenerate and save a Data Source Package (DDSP file) to a temporary location on file system and then upload it to the corresponding SharePoint document library.

4. Synchronize the template

Open the Docentric document types form and locate the Sales Docentric Template Library document type. Select the SalesOrderPreview template and click the Synchronize button.

We have to synchronize a template only if any of the following properties have changed:

  • Language
  • Template Path (actually only if the path of the parent Document type has changed)
  • Name of the Data Source Provider class or query
  • Primary table (determined by Data Source Provider)
  • Sample record from the Primary Table (Primary table RecId)
  • Flag Include company logo
  • Flag Include display methods

If we synchronize the template, we must activate it again.

5. Generate the document from the template

Check the formatting and make sure that everything else works as expected by generating the ‘Sales Order Preview’ document from the corresponding template on the Sales Orders list page.

Generated ‘Sales Order Preview’ document for Sales Order with ID ‘000003’ is shown after the generation is done.

Report previewing during template design uses formatting from the Windows regional settings on the user’s AX client computer whereas the reports generated from the AX client have formatting controlled through the AX user’s setup in the Options section.

Resources

Data source provider class Data source (DDSP file) SalesOrderPreview Template

See also

Word Template Examples >>
How to Use Labels with Word Document >>
How to Design Templates with Docentric AX Template Designer >>
How to Write a Data Source Provider Class >>
Docentric Data Source Packages (DDSP files) Overview >>

IN THIS ARTICLE