Example 3: Purchase Order Print Management Report
In this example we want to prepare a purchase order with all the necessary information. We will include logo and contact information in the first page header. That the company logo will not be placed as a static picture, but rather a placeholder that is data-bound to the logo image data field. The footer will contain information about the current page, date and time of the report and the information about who requested the report.
Purchase order items will be displayed in a table. Another table will contain totals. We will also use text boxes for some parts of the document.
The generated document will look like in the picture below:
Step by step instructions
This document will contain quite a bit of MS Word formatting features. We will not go into details here, as you can refer to MS Word documentation if necessary.
We will create a new document and make it a Docentric AX template by clicking the Use As Template button on the DOCENTRIC AX ribbon tab. The file dialog will open where we must choose the Data Source Package file (.ddsp).
Step 1: Setting page layout
We will now set the page layout for our template document as shown below:
Step 2: First page header
Headers and footers can contain any Docentric AX tagging element(s).
The first page header will contain a table with one row and three columns. First table cell will contain the logo image and the company name, the second cell will contain the address and the third cell will contain some other company information.
Position of the content in individual table cells will be controlled by choosing left, right and vertical cell alignment and by setting cell padding.
We will need to insert an appropriate tagging element for each data field. The image in the first column, encircled with red, is an Image tagging element representing the logo. Other items, encircled with blue, are Field tagging elements representing string data fields.
Inserting the logo image placeholder
We place the cursor in the first column and insert a new Image tagging element by clicking the Image button on the DOCENTRIC AX ribbon tab. Data for the image will come from the Data Source, so we set the data binding accordingly:
The Element Tree pane now looks as follows:
Note that we don’t want the logo to be of the original image size in the generated document, but rather of the placeholder size set in the template. Hence, the Size Mode property was set to “Use Placeholder Size”. To fine-tune the size of the placeholder right-clicking on the Image tag and select Format Picture:
Remember, that the selected Data Source Package also contains test data used for the previewing purpose. You can get the preview of the generated document any time (DOCENTRIC AX -> Preview).
Inserting other placeholders
Just below the image, we will now insert our first Field tagging element. The cursor must be positioned outside the Image tag but still inside the first table cell. Since the company information is part of the General Data Section, we set the binding to General Data => CompanyInfo/@Name.
The second table cell will contain the address for which we add the Field tag bound to General Data => CompanyInfo/DirPartyPostalAddressView/@Address.
The inner text of the Field tag is a long because it contains the binding path text and is hence a bit unreadable. Note that you can always abbreviate text inside Field tags for the sake of preserving “natural” layout:
It is important to understand that changing the text inside a Field tagging element does not change its data binding.
We repeat the process for the placeholders in the third cell:
|Label||Binding Source||Binding Path|
First page header is now formed.
Step 3: Footers
In our next step we will add footer to the first page. To edit the footer we choose INSERT -> Footer -> Edit Footer. Then ad contents as follows:
We have static text “Page | ” in first row on the left which is followed by MS Word’s “Page” field, which displays the current page number.
In the second row on the left side we insert the Field tag and bind it to General Data => Misc/@SessionDateTime.
On the right we have inserted a text box and positioned it as needed. In the first line in the text box we type static text “Requester”. In the second line we place two Field tags, bound to General Data => HcmWorker/@Name and Genera Data =>HcmWorker/@Title.
The first page footer is now formed.
The non-first page footers
We want the footer for other pages to look exactly the same as the first page footer, so we will just copy the contents of the first page footer into the default footer.
Step 4: Other page headers
There will be no header contents after the first page. In our document we see, that the second page has an empty header, which is what we want, so we don’t have to do anything here.
Step 5: Document title
Now we will start adding content into the body of the template. First we will add the title of the document. Title is dynamic and comes from the data, so we insert a Field tag and bind it to Parameters => @DocumentTitle).
Step 6: Vendor information
Here we want to have static text “Vendor” and the vendor’s name and address. We insert two Field tags and bind them to the data (Main Data => PurchPurchaseOrderHeader/@VendName and Main Data => PurchPurchaseOrderHeader/@VendAddress).
Step 7: Purchase order identification information
The next information we want to add are PO number, order date and the payment terms. We will wrap this content in a text box.
We have four Field tagging elements in this text box along with some static text.
Data Bindings are as follows:
|Label||Binding Source||Full Field tag Binding Path|
|Order date:||Main Data||PurchPurchaseOrderHeader/@PurchOrderDate|
|Delivery terms:||Main Data||PurchPurchaseOrderHeader/@DlvTerm|
Since the @PurchaseOrderDate Field tag is bound to a date-time value, we also need to set a preferred format string for it to “d” which specifies short date format.
Step 8: Purchase order lines
PO lines will be displayed in a table. This table will have a header row with column names and one row acting as a template for a single PO line.
Let’s insert a table with seven columns and three rows. Add column header text and format the table as in the picture below:
Marking the template table row with a List tag
We need to mark the table row that will serve as PO line repeating block template. To do this, we will select the entire third table row and click on the List button on the DOCENTRIC AX tab.
With the List tag inserted, we have to bind it to the PO line records. Our list will be bound to Main Data => PurchPurchaseOrderHeader/PurchPurchaseOrderTmp. Data collection will be sorted by Name.
List tag now spans across the entire third row.
Adding Field tagging elements for each line’s data field
If you generate the preview at this point, you will see that the table rows have been generated for each PO line, but all are empty. This is because we did not specify the PO line data fields yet. For each PO line data field we will add a Field tag into the cells of the template (third) row. By doing so, the Field tags will be nested inside the List tagging element.
The first cell will display the sequence number, so we just set-up the paragraph numbering properly.
We insert placeholders (Field tags) for each PO line data field:
|Column||Binding Source||Full Field tag Binding Path||Format string|
|Line amount||Data Context||@LineAmount||n2|
|Line amount||Data Context||@CC|
The columns, which display financial information contain two Field tags: one for money value and the other for currency. Discount column cell contains three Field tags. All the PO line Field tags represent data fields of the »current« line and hence all the Field tags have the Binding Source set to Current Data Context
Note that the content in the template table row is not limited to one Field tag per cell. You can insert any number of tagging elements in a single cell and combine them with static text freely as you like.
The template should look like this:
Step 9: Table displaying totals
Totals will be displayed in a separate table as shown in the picture below:
Tax and Total data fields are present in the data source, so we will include them with Field tagging elements, bound to Main Data => PurchPurchaseOrderHeader/@SumTax and Main Data => PurchPurchaseOrderHeader/@Amount. These cells will also contain currency information (Main Data => PurchPurchaseOrderHeader/@CurrencyCode).
Subtotal (i.e. sum of the Line Amounts), however is not present as separate data field in our data source, so we will use Summary Field tagging element that will calculate this value by aggregating some other data field. We have to bind the Summary Field tag to PO Line records and we also have to set the Aggregate data binding to tell which PO Line data field will be used in the aggregate function (Value = Main Data => PurchPurchaseOrderHeader/PurchPurchaseOrderTmp, Aggregate = @LineAmount, Function = Sum, Ignore Nulls = true, Format String = n2).
When we are done, we get the following result:
Step 10: Delivery address
The Delivery details will be added next. We need to insert static text “Delivery address:” and two Field tags with the following binding properties:
|Binding Source||Full Field tag Binding Path||Abbreviated Field tag content|
After the content has been added and styles applied the template should look like this:
Step 11: Additional notes
Finally we want to include additional notes in separate text box. We insert some static text and the Field tag, and bind it to Main Data => PurchPurchaseOrderHeader/@Notes.
Conditional Content in notes
At the end of the text box we want to conditionally display the “Additional Information” content. By “conditional content” we mean a content that will be included or excluded from the generated document in regard to some concrete value at document generation time.
Our conditional content consists of static text “Attention information:” and a Field element bound to Main Data => PurchPurchaseOrderHeader/@ReqAttention. In order to make this content conditional, we need to wrap the content inside an If tagging element and bind the tag to a Boolean data field or XPath returning a Boolean value. In our case we bind the If tag to Main Data => PurchPurchaseOrderHeader/@ReqAttention != ‘’ by using XPath Editor. As a result, the wrapped content inside the If tag will only get rendered if the @ReqAttention value will not be empty.
Preview it (DOCENTRIC AX -> Preview) to make it shine forth in all its glory!