Conversion error in a template

Dear support,

We have orders with multiple order lines in D365FO which are not correctly displayed in our template. If you look at the screenshot you see that there are also conversion errors in the document.

image

Are you able to assist us with this?

Regards,
Michael

Hi Michael,

This happens because of the wrong bindings of the fields in the SalesInvoiceTmp list. When you list the lines, you want to refer to the value of the field from the current line and not from all the lines in the list.

When the binding source of a field inside a list is set to MainData, this leads to wrong results as soon as the list displays more than one SalesInvoiceTmp record:

Your data source contains two such records, and the values of the string-type data fields (highlighted in yellow below) from all the lines are concatenated, while the numeric and date-time types of data fields (highlighted in blue) result in conversion errors:

Please note the binding source in the Xpath expression editor is set to MainData. When MainData is selected as the binding source inside a list tagging element, this will most likely result in either concatenated strings or conversion errors:

But if you select Data Context as the binding source, this leads to correct results:

Read a value from a single record

There were more invalid bindings in the Totals section at the end of the template:

Here is a bit different situation than inside a list tagging element in the previous table. Inside the list, we want to read the value of a data field from the current invoice line (by using the Data Context binding source).

On the other hand, in the Totals section we don’t have a list tagging element. We are here configuring the binding of a top-level field tagging element and not a child tagging element of a list or group tagging element. In this case, we will not even have the option to apply the Data Context binding source for the StandardCurrency data field as it is only available for child tagging elements (e.g., elements inside a list or a group).

So we need to bind the field to MainData. Your original Xpath expression was:

SalesInvoiceTmp/@StandardCurrency

In this case, the field tagging element reads the values of the StandardCurrency from all SalesInvoiceTmp data records in the datasource. As the value of the StandardCurrency data field is the same in all SalesInvoiceTmp data records, the easiest way to solve this is to read the value of the data field from the first record only. We can do this by inserting the [1] in the Xpath expression:

SalesInvoiceTmp[1]/@StandardCurrency

Please let me know if the results are now as expected.

I logged a similar question, Can someone please check