How to Create a Word Document with DSP Query
Our goal in this tutorial is to show how to create a Word document with DSP (Data Source Provider) query assigned to a Docentric Template Library.
Let’s say that we want to create a 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. In order to do that, we should take the following steps:
- Create a DSP query for this document.
An AX query that comprises the required data of the currently selected sales order. We can use more than one query but they all must have Primary table (SalesTable) set as their primary data source. - Generate the Data Source Package file using this DSP query.
The document data source containing sales order sample data is created by Docentric AX Framework using this DSP query. It is saved in a physical file called Data Source Package. - Create and design the document template using the generated Data Source Package.
- Synchronize the template, i.e. add it to the Sales Template Library.
- Activate the template.
- Generate the document from the template on the Sales Orders list page in a standard way.
Let’s start with our task. First, we need to create a new Docentric document type which must be a Template Library for Sales documents, see how. Let’s assume we’ve already created it as a Template Library with templates stored on file system and named it as ‘SalesTL_FS’. We also specified Folder as the template location.
When we want to update the document with new data and/or change its template design, we should take additional steps:
- Update the DSP query 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.
On how to update a document, i.e. its template you can learn here.
1. Prepare a DSP query and generate the document data source
To design a document template with the Docentric AX designer we need a document data source saved in a physical file. This file is called Docentric Data Source Package (DDSP) file.
In other words, to be able to design a template for a document, we need to generate a corresponding DDSP file first. We can do this in two ways: with a dedicated class (Data Source Provider class) or with one or more queries (Data Source Provider query).
In this tutorial we will consider only DSP (Data Source Provider) Query based documents; DSP Class based documents have been explained in the previous tutorial.
So let’s start with creating our DSP query for ‘Sales Order Preview’ document. SalesTable is going to be our Primary table so the query must include SalesTable table as a primary data source and SalesLine table as a child data source.
Click the Generate DS button on the Docentric document types form.
The form Generate data source is opened. Enter a Template ID, e.g. SalesOrderPreview_FromQuery, select Query as Data source provider and click the button Add query.
A pop-up form is opened where we need to select or type the name of our DSP query –> SalesOrderDocumentDsProviderQuery.
1.1. Generate the Data Source Package
When we return to the opened Generate data source form, we will notice that Data source provider queries list box contains our query SalesOrderDocumentDsProviderQuery. This also caused Primary table to be determined, in our case as SalesTable. Furthermore we can specify whether the Company logo is going to be included in the generating Data Source Package. We can also decide to use a particular record (Primary table RecId) of the Primary table, with more representative data and hence ensure more realistic preview during coming template design. We can also include or exclude table display methods from query data sources.
By clicking the Generate data source button, the data source for the document is generated and saved in a physical file. This file is called Data Source Package and contains the data provided by the selected DSP query. In our case, it contains SalesTable record with RecId = 5637144576 (SalesId = ‘000002’) and all child SalesLine records, according to the definition of our SalesOrderDocumentDsProvierQuery DSP query. The generated Data Source Package is going to be used in the document ‘Sales Order Preview’ template design.
Note that the Data Source Package file name is the same as the Template ID.
About Docentric Data Source Packages (DDSP files) that represent design-time data sources intended for designing templates of Docentric documents and reports you can learn more here.
2. Create and design the template
Create a new ordinary Word document and name it as the generated DDSP file (i.e. as the Template ID), in the same file location.
This Word document, SalesOrderPreview_FromQuery.docx, will be our template for the ‘Sales Order Preview’ document.
Follow the instructions from the second step till end in the tutorial How to Create a Word Document with DSP Class assigned to a Docentric Template Library. All remaining steps are almost identical. Just as a reminder, here they are:
- Create and design the template.
- Synchronize the template, i.e. add it to the Sales Template Library. Activate the template.
- Generate the document from the template on the Sales Orders list page in a standard way.
Resources
Data source provider query Data source (DDSP file) SalesOrderPreview Template
See also
How to Update an Existing Word Document >>
How to Use Labels with Word Document >>
How to Design Templates with Docentric AX Template Designer >>
How to Create a Word Document with DSP Class >>
Word Template Examples >>