Example 5: Purchase Order Basic Report

Objective

In this example we want to create similar report as in example #3, but we want to control whether some parts of the report will be included in the final document or not. These parts will be conditionally rendered and included in the final document only if certain conditions will be met. This report will also include discount and payment terms information.

Final result

The final result will vary based on the values that control whether to include or exclude the conditional content. If the tax information will not be included in the final document then the final document will look like in the figure below:

If we want the tax information to be included, however, then the generated document will look like in the following figure:

Step by step instructions

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 corresponding Data Source Package file (.ddsp).

Step 1: Copying common parts of the report from example #3

Our report will contain parts, which are exactly the same as in the report #3, so we will simply copy and paste them. These are the parts that can be copied:

  • First page header.
  • First page footer and default footer.
  • Upper part of the body up to and including Purchase order items.

Some names of the data fields are different in the data source as in example #3, so we will check and correct the binding information, if necessary, as follows:

First page header:

Data Tagging Element Binding Source Binding Path
Logo Image General Data CompanyInfo/@Logo
Company name Field General Data CompanyInfo/DirPartyPostalAddressView/@Address
Address Field General Data CompanyInfo/@Name
VAT Field General Data CompanyInfo/SalesTax/@VATNum
Email Field General Data CompanyInfo/@Email
Phone Field General Data CompanyInfo/@Phone
Fax Field General Data CompanyInfo/@Telefax

First page footer and default footer:

Data Tagging Element Binding Source Binding Pat
Session date and time Field General Data Misc/@SessionDateTime
Requester’s name Field General Data HcmWorker/@Name
Requester’s title Field General Data HcmWorker/@Title

Body:

Data Tagging Element Binding Source Binding Path
Purchase order line List Main Data PurchTable/PurchLine
Description Field Current Data Context @Name
Qty Field Current Data Context @PurchQty
Unit Field Current Data Context @PurchUnit
Price Field Current Data Context @PurchPrice
Currency code Field Current Data Context @CurrencyCode
Discount Field Current Data Context @DiscAmount
Discount Field Current Data Context @DiscPercent
Line Amount Field Current Data Context @LineAmount

Our report template should look like in the following figure below:

Step 2: Adding conditional content with tax information

Depending on the value of Parameters => @IncludeSalesTax data field we will conditionally include or exclude tax information at document generation time.

We will insert an If tagging element and enter the expression in XPath Editor that will determine the condition when this conditional content will be included in the final document. We do this by using Binding Control and XPath Editor, where we enter expression: @IncludeSalesTax = 'true'.

Note: @IncludeSalesTax is in Parameter Data Source so the binding information for the If tag is actually Parameters => @IncludeSalesTax = ‘true’.

The conditional content will wrap a separate table with subtotal, tax and total information, which are bound to the data fields as follows:

Data Tagging Element Binding Source Binding Path
Subtotal Field Main Data PurchTable/@SubtotalAmount
Tax Field Main Data PurchTable/@TaxAmount
Total Field Main Data PurchTable/@TotalAmount
Currency code Field Main Data PurchTable/@CurrencyCode

Our report should look as follows:

Step 3: Adding conditional content without tax information

Now we will add conditional content for cases when we just want the total amount and no tax information. We will insert an If tagging element and bind it to Parameters => @IncludeSalesTax. In XPath Editor we will write the expression which will determine the condition when this conditional content will be included in the final document: @IncludeSalesTax = 'false'.

As you can see, this condition has to be mutually exclusive with the condition in step 2, because we want just one of these two conditional contents in the final document.

Conditional content will wrap a separate table with the total amount information, using the following Field tags:

Data Tagging Element Binding Source Binding Path
Total Field Main Data PurchTable/@TotalAmount
Currency code Field Main Data PurchTable/@CurrencyCode

Step 4: Discount information

Discount information will show discount amount and description if applicable. We will need two field tags, bound to data as follows:

Data Tagging Element Binding Source Binding Path
Discount amount Field Main Data PurchTable/@CashDiscount
Currency code Field Main Data PurchTable/@CurrencyCode
Discount description Field Main Data PurchTable/@CashDiscDescription

We will wrap the discount description Field tag in an If tagging element and enter the following expression by using XPath Editior: PurchTable/@CashDiscount != 0 (PurchTable/@CashDiscount Binding Path comes from Main Data Binding Source). Discount description will be included in the final document only when this expression will be true.

Step 5: Payment terms and payment mode information

Payment terms will always be included in the final document. Payment mode, however, will be included only when it is not empty. We will need two field tags, bound to the data as follows:

Data Tagging Element Binding Source Binding Path
Payment term Field Main Data PurchTable/@PaymTerm
Payment mode Field Main Data PurchTable/@PaymMode

We will wrap payment mode Field tag in an If tagging element, bind it to Main Data => PurchTable/@PaymMode data field and then enter the following expression by using XPath Editior: PurchTable/@PaymMode != ''. Payment mode will be included in the final document only when this expression will be true.

Step 6: Delivery address and attention information

We will insert a text box and place two Field tags in it. The field tags will be bound to data as follows:

Data Tagging Element Binding Source Binding Path
Delivery address Field Main Data PurchTable/@DeliveryAddress
Attention information Field Main Data PurchTable/@ReqAttention

Again we want that the attention Field tag is included in the final document only when it is not empty. We will wrap attention Field tag in an If tagging element, bind the If tag to Main Data => PurchTable/@ReqAttention data field and then enter the following expression by using XPath Editior: PurchTable/@ReqAttention != ''.

Our report is now finished and we can preview it to see how it looks at this point.

Step 7: Changing data values to trigger different conditional contents

We will now see how we can change data values in the test data source. Remember, that each report contains data schema information and test data, supplied by the .ddsp file.

By changing the underlying data on the fly, inside the template, we can control which conditional contents to include in the report. This is very useful feature to test if our report renders properly.

We can modify the test data by using the built-in XML editor:

  1. Open Data Source pane (Docentric AX -> Data Source).
  2. In the Data Source tree view select the Parameters data section node.
  3. Click the Edit sample data button as shown in the figure above.
  4. The XML Editor opens. Modify the XML attribute as needed.
  5. Click the OK button.

Preview the report to see the effect of the change.

Resources

Data source (DDSP file) Template

IN THIS ARTICLE