We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

MailMergeWithRegions not working when DataRelation has multiple columns

I am using Aspose words for Jave version 18.7. When I create DataRelation with more than one columns it does not give the desired output. DataRelations with just one column works fine. I reviewed an existing ticket
and modified the code from .Net to Java to depict the problem. The child region does not honor the relationship.

Template is attached for reference testRelations.zip (11.7 KB)

and code is as follows
Document doc;
try {
doc = new Document(“C:\DataRelation\testRelations.docx”);

			doc.getMailMerge().executeWithRegions(GetNestedData());

			doc.save("C:\\DataRelation\\out1.docx");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}	

private static DataSet GetNestedData() {
	DataSet ds = new DataSet();

	DataTable master = new DataTable("master");

	master.getColumns().add("id1");

	master.getColumns().add("MasterName");

	master.setPrimaryKey(new DataColumn[] { master.getColumns().get("id1") });

	DataTable parent = new DataTable("parent");

	parent.getColumns().add("id1");

	parent.getColumns().add("id2");

	parent.getColumns().add("ParentName");

	parent.setPrimaryKey(new DataColumn[] { parent.getColumns().get("id1"), parent.getColumns().get("id2") });

	DataTable child = new DataTable("child");

	child.getColumns().add("id1");

	child.getColumns().add("id2");

	child.getColumns().add("id3");

	child.getColumns().add("ChildName");

	child.setPrimaryKey(new DataColumn[] { child.getColumns().get("id1"), child.getColumns().get("id2"),
			child.getColumns().get("id3") });

	ds.getTables().add(master);

	ds.getTables().add(parent);

	ds.getTables().add(child);

	DataRelation rl1 = new DataRelation("r1", new DataColumn[] { master.getColumns().get("id1") },
			new DataColumn[] { parent.getColumns().get("id1") }, false);
	
	ds.getRelations().add(rl1);

	DataRelation rl2 = new DataRelation("r2",
			new DataColumn[] { parent.getColumns().get("id1"), parent.getColumns().get("id2") },
			new DataColumn[] { child.getColumns().get("id1"), child.getColumns().get("id2") }, false);  
	
	ds.getRelations().add(rl2);

	for (int i = 0; i < 2; i++)
	{
		master.getRows().add(new Object[] { i, "Master_"+ i });
		for (int j = 0; j < 3; j++)
		{
			parent.getRows().add(new Object[] { i, j, "Parent_" + i + "_" + j});
			for (int k = 0; k < 3; k++) {
				child.getRows().add(new Object[] { i, j, k, "Child_" + i + "_" + j + "_" + k});
			}
		}
	}
	return ds;
}

@edelvecc

Thanks for your inquiry. We have tested the scenario and have managed to reproduce the same issue at our side. For the sake of correction, we have logged this problem in our issue tracking system as WORDSJAVA-1943 . You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

The issues you have found earlier (filed as WORDSJAVA-1943) have been fixed in this Aspose.Words for .NET 18.12 update and this Aspose.Words for Java 18.12 update.