Hi James,
Thanks for your inquiry.
*jrsaspose:
For your statement, in what context are we talking about not using dot in the mail merge fields? Inside a code block? Inside the Word document? Or some other context?*
As I shared earlier, please do not use dot (.) in mail merge field in your template document (e.g Word document) if you are using custom data source, such as a list of objects. If you are implementing IMailMergeDataSource interface, dot (.) is not recommended in mail merge fields and data source object as well.
*jrsaspose:
Am I to understand that the differentiation you are trying to identify is using the dot notation in the context of an actual code block of the GetChildDataSource method (e.g. Using dot notation as a test for an if statement such as if(Address.Street == “abc”))? If this is the case, it would be helpful to indicate in documentation “then do not use dot notation in the code to reference a mail merge field.” The second scenario is using dot notation in a mail merge field, but within the context of a Word document. If your explanation is to indicate the fact that I created any implementation of the GetChildDataSource method that I should not be using dot notation, then I am not using the IMailMergeDataSource correctly? However, if that’s a problem, the examples in the programmers guide are incorrect.*
Please check the following code example for the issue using dot (.) in mail merge fields.
If your template has mail merge filed e.g Item.Name, Aspose.Words can not determine at the time of field “Item.Name” mailmerge - is this field name “Item.Name” or is this related object “Item” with property “Name”.
I have attached the input template document with this post. I suggest you please check the code example shared at following documentation link.
https://reference.aspose.com/words/net/aspose.words.mailmerging/imailmergedatasource/getchilddatasource/
class TestDataSource : IMailMergeDataSource
{
private int _index;
public bool MoveNext()
{
return _index++ < 5;
}
public bool GetValue(string fieldName, out object fieldValue)
{
switch (fieldName)
{
case "SimpleName":
fieldValue = "Simple item name";
return true;
case "Item.Name":
fieldValue = "Dotted item name";
return true;
default:
throw new Exception("Unexpected fieldName " + fieldName);
}
}
public IMailMergeDataSource GetChildDataSource(string tableName)
{
switch (tableName)
{
case "Item":
throw new Exception("This is not a collection. It is part of my field name.");
default:
throw new Exception("Unexpected tableName " + tableName);
}
}
public string TableName
{
get { return "Collection"; }
}
}
var document = new Document(MyDir + "TestMergeTemplate.docx");
document.MailMerge.ExecuteWithRegions(new TestDataSource());
*jrsaspose:
I definitely want to be clear on what is supported and what is not supported. If this is as significant of an issue as it appears to be, more documentation would be helpful. Maybe your documentation can show an example of what’s not supported. I have yet to see a clear example of what shouldn’t be done in the documentation.*
As I shared earlier, Aspose.Words fully support the mail merge features. The issue using dot (.) in mail merge fields is described in above code example. The usage of simple mail merge and mail merge with regions are well explained in documentation. Please read following documentation articles.
https://docs.aspose.com/words/net/mail-merge-and-reporting/
https://docs.aspose.com/words/net/types-of-mail-merge-operations/
*jrsaspose:
As I wrote all of this, I looked back on the thread once again. I believe I have figured out the scenario you are trying to prevent may be in the getValue method, not the getChildDataSource. Is that where the dot notation should not be used? Is there anywhere else? It seems that quite a bit more information should be given in the programmers guide to help people be compliant with the Aspose usage and what should or shouldn’t be done. I left the text above in case I have not interpreted correctly.*
I have explained this issue in above code example. We will update our documentation about this issue detail that the dot should not be used in the mail merge field names.
Please check the code example at following
forum link about using dot (.) in mail merge field name. The code
example at following forum link use DataSet object in
MailMerge.ExecuteWithRegions method.
https://forum.aspose.com/t/49899
You can merge attributes of a field using the syntax Object.Attribute e.g Address.Street. However, implementation of IMailMergeDataSource does not allow dot (.) in mail merge field name (in template document and data source).
Hope this clear the detail of issue ‘IMailMergeDataSource.GetChildDataSource is called when mail merge filed contains dot (.)’. Please let us know if you have any more queries, we will be happy to help you.