Get a list of template fields from a document (LINQ Reporting Engine)

Is there a way to get a list of all the fields used in a document template (e.g. a .docx file) when using the LINQ Reporting Engine?

For example the document has template fields referred directly like <<[Client.FullName]>> also used in different expressions like <<[Client.DateOfBirth]:“dd-mm-yyyy”>>

If there is no method in the API to get a such list, then maybe there is a regular expression you would recommend to use

P.S. It’s understood that there is a method for MailMerge - Document.MailMerge.GetFieldNames(). But the question is about the LINQ Reporting Engine.

@lawmaster,

Most likely, you request this feature because it is present in standard Mail Merge engine of Aspose.Words. However, LINQ Reporting Engine expressions are more complex than just field/variable references. So, we cannot expose just field names without exposing the whole expression tree. But this is a big API change (that can be compared with a document tree, for example) which would greatly complicate Aspose.Words, so we try to avoid it.

Also, LINQ Reporting Engine was designed in a way enabling to avoid old mail merge workarounds to get the things done. So most likely, there is a way how you can make it work in your scenario without getting a list of fields/variables, etc.

Please elaborate your scenario further as to why do you need this list and parse Word documents to retrieve all instances of LINQ Reporting Engine variables. This will help us to understand your scenario, and we will be in a better position to address your concerns accordingly.

Hi Awais,

Use cases
I’ve got two independent use cases for the feature request:

  1. As a document produced from the template can have tens of pages with the Template Fields scattered across the whole document, then checking that all fields have data and were merged correctly is a time-consuming process. As a solution for that, the application can show a list of all the Template Fields and the values, which will appear in the document prior the merge. To do so I, as a developer, need to fetch all the Template Fields from the document to resolve their values.
  2. Due to lack of support of C# dynamic objects (WORDSNET-16421 and WORDSNET-12148), we can supply a flatten out DTO as a dictionary toBuildReport() method, where the keys for nested properties will look like Contact__Address__Country (so the ‘.’ is replaced with ‘__’). But as it doesn’t look intuitive, we could allow keeping the traditional Template Field naming in the document (like Contact.Address.Country) and replace the ‘.’ to ‘__’ in the template Dcoument before calling BuildReport() method.

Regular expression
I understand that you don’t have the requested method, then would you be able to provide a regular expression you’re using for fetching the Template Fields.

I came up with the following expression: (?<=<<\s|\w*\[|\G)([^\]\[\.]+)\.(?=[^][]*\]), but it may not be fully aligned with your Template Syntax.

Best regards,
Alex

@lawmaster,

Thanks for the additional information. We have logged your requirement in our issue tracking system. The ID of this issue is WORDSNET-17454. We will further look into the details of this problem and will keep you updated on the status of this issue. We apologize for your inconvenience.

Can you guys PLEASE implement this feature (WORDSNET-17454)! This has been requested for over five years now by multiple paying customers! This functionality is critical for any code that is using the LINQ Reporting Engine in any meaningful way. Please implement ASAP!

Our organization would greatly benefit from this feature. We have hundreds of document templates that use numerous data sources with different data models. Right now, we have no way of validating that a change to a datasource will not break a document template due to a field reference having been removed or changed.

@wrensmith @ted-1 Unfortunately, implementation of this feature is still postponed. I have added your requests to the appropriate issue in our defect tracking system. We will keep you updated and let you know once the feature is implemented or we have more information for you. Please accept our apologies for your inconvenience.