Error when merging three levels deep mail merge region

Hi everybody,

I have a problem when merging data in a document using a three-levels deep mail merge region. I have attached both the template and the output document.

The region is filled using the following code:

DataTable documenti = new DataTable(this.getDocumenti(), “documenti”);
DataTable mansioni = new DataTable(this.getMansioni(), “mansioni”);
DataTable rischi = new DataTable(this.getRischiMansioni(), “rischi”);

DataSet ds = new DataSet();

DataTableCollection dtc = ds.getTables();
dtc.add(documenti);
dtc.add(mansioni);
dtc.add(rischi);

DataRelationCollection drc = ds.getRelations();
drc.add(new DataRelation(
“DocumentiMansioni”,
“documenti”,
“mansioni”,
new String[] {“id_azienda”, “id_sede”, “revisione_documento”},
new String[] {“id_azienda”, “id_sede”, “revisione_documento”}
));
drc.add(new DataRelation(
“MansioniRischi”,
“mansioni”,
“rischi”,
new String[] {“id_mansione”, “id_azienda”, “id_sede”, “revisione_documento”},
new String[] {“id_mansione”, “id_azienda”, “id_sede”, “revisione_documento”}
));

[…] // now perform merging

The table “documenti” contains the following fields:

  • id_azienda
  • id_sede
  • revisione_documento
  • rischio_residuo_azienda
  • nome_indice_rischio_azienda
  • ragione_sociale sede

The table “mansioni” contains the following fields:
  • id_mansione
  • id_azienda
  • id_sede
  • revisione_documento
  • rischio_residuo_mansione
  • nome_indice_rischio_mansione

And lastly, the table “rischi” contains the following fields:
  • id_rischio
  • id_mansione
  • id_azienda
  • id_sede
  • revisione_documento
  • probabilita
  • gravita
  • fattore_rid
  • rischio_residuo

So, I would say that the relationship are defined correctly, but the result produced is not correct. I have also attached an example of correct result, but please do not consider the color of the cells in this example.
Hi Matteo,

Thanks for your inquiry. Could you please upgrade to latest version of Aspose.Words i.e. v11.11.0 and let us know how does it go on your side? You can download it from the following link:
http://www.aspose.com/community/files/72/java-components/aspose.words-for-java/default.aspx

In case the problem still remains, could you please also attach your complete source code (getDocumenti method and the MailMerge logic you're using on your side) here to be able to reproduce the same issue on my side. I will investigate the issue on my side and provide you more information.

Best regards,

I cannot upgrade to version 11.11 right now, we are all still using version 10.4

Could you please tell me if you got it right on your side using latest version?

Thanks.

Hi Matteo,


Thanks for your request. Please post your complete source code; I will test your scenario with the latest version of Aspose.Words (11.11.0) on my side and share my findings with you.

Best regards,

Here is the code of the data-gathering methods:

protected ResultSet getDocumenti() throws Exception {
try {
return this.query(
"SELECT t1.*, " +
"t2.ragione_sociale_sede " +
"FROM gen_13_1 as t1 " +
"JOIN agews_anagrafiche_sedi as t2 USING(id_sede, id_azienda) " +
"WHERE " + this.getSqlSearchDocumenti() + " " +
“ORDER BY ragione_sociale_sede”
);
}
catch (Exception e) {
throw this.error(“Impossibile caricare l’elenco dei documenti nella valutazione per mansione”, e);
}
}

protected ResultSet getMansioni() throws Exception {
try {
return this.query(“SELECT * FROM gen_13_1_mansioni WHERE " + this.getSqlSearchDocumenti() + " ORDER BY mansione”);
}
catch (Exception e) {
throw this.error(“Impossibile caricare l’elenco delle mansioni valutate”, e);
}
}

protected ResultSet getRischiMansioni() throws Exception {
try {
return this.query(“SELECT * FROM gen_13_1_mansioni_rischi WHERE " + this.getSqlSearchDocumenti() + " ORDER BY rischio”);
}
catch (Exception e) {
throw this.error(“Impossibile caricare l’elenco dei rischi delle mansioni valutate”, e);
}
}

During my tests, the value returned by this.getSqlSearchDocumenti() was id_azienda = 3 AND ((id_sede = 3 AND revisione_documento = 3) OR (id_sede = 14 AND revisione_documento = 2)).

I have also attached a .txt file which contains a CSV of the data returned by the methods described above.

The data is then merged by calling

com.agews.suite626.report.Report.merge(doc, ds)

and this is the implementation:

protected static Document merge(Document doc, DataSet data) throws Exception {
doc.getMailMerge().executeWithRegions(data);
return doc;
}

Hi Matteo,


Thanks for the additional information. In order to reproduce this issue on my side, I transformed your CSV file into three equivalent XML data files (attached). I then produced an output report using the latest version of Aspose.Words (11.11.0) and attached it here for your reference. You can see that the final report is coming out nicely. If we can help you with anything else, please feel free to ask.

Best regards,

Yes, I can see that it works with latest version.

I would like to ask one last question: given a three-level deep structure like this one, can you please confirm that I have to define relationships only between level 1 and 2, and level 2 and 3, but not between level 1 and 3?

Thanks.

Hi Matteo,


Thanks for your inquiry. Yes, in your case, you need to define two relationships between levels 1 and 2 and levels 2 and 3. If we can help you with anything else, please feel free to ask.

Best regards,