Use Nested Mail Merge Field inside IF Field to Conditionally Show Hide Table in Word DOCX Document using JAVA

We have recently upgraded Aspose.word from 13.5.0 to 20.4 and running in to issue with If condition on table.
Basically {IF {MERGEFIELD some} = “test” “YES” “NO”} is working for simple text. But if we want to show/hide table then it is not working. In above example, Instead of “YES” we want to show a table.

Could you please provide suggestion on this issue?

@amitpatelbnft,

Please check following documents where I placed a Table inside True part of IF field.

Following C# code will show the Table while specifying false to merge field will hide it.

Document doc = new Document("E:\\Table inside true part of IF field\\Table inside true part of IF field.docx");
doc.MailMerge.Execute(new String[] { "show" }, new String[] { "true" });
doc.Save("E:\\Table inside true part of IF field\\20.5.docx");

Hope, this helps.

Could you please test “false” result in order do not show the table?

@amitpatelbnft,

Sure, I have attached both the outputs (generated by specifying “true” & “false”) here for your reference:

It seems if we have “if statement” with in «TableStart:objectList» … «TableEnd:objectList» then it is not working correctly.

@amitpatelbnft,

To ensure a timely and accurate response, please ZIP and attach the following resources here for testing:

  • Your simplified input Word document
  • Aspose.Words 20.5 generated output DOCX file showing the undesired behavior
  • Your expected DOCX file showing the desired output. You can create this document by using MS Word.
  • Please also create a standalone simple console application (source code without compilation errors) that helps us to reproduce your current problem on our end and attach it here for testing. Please do not include Aspose.Words DLL files in it to reduce the file size.

As soon as you get these pieces of information ready, we will start investigation into your scenario and provide you more information. Thanks for your cooperation.

@awais.hafeez
It seems there is bug in Aspose.word with getChildDataSource and “if statement”.It looks like getChildDataSource() is not calling when we have “if statement”. Please find the sample code where we are able to reproduce this issue.AsposeTestProject.zip (857.4 KB)

@amitpatelbnft,

We have logged this problem in our issue tracking system. Your ticket number is WORDSNET-20477. We will further look into the details of this problem and will keep you updated on the status of the linked issue. Sorry for the inconvenience.

@awais.hafeez could you please provide ETA on this? Thanks!

@amitpatelbnft,

I am afraid, we are currently doing analysis of this issue and there is no ETA available at the moment. Once the analysis of this issue is completed and the root cause is determined, we may then be able to calculate and share the ETA (time frame) with you. We apologize for your inconvenience.

@amitpatelbnft,

Regarding WORDSNET-20477, we have made a few changes to the code; please check on your end and let us know if the following code changes (mRecordIndex = 0, updateFields()) are acceptable for you?

public void SimpleTest() throws Exception
{
    test("testTemplateWithIF.docx");
    test("testTemplateWithoutIF.docx");
}

private void test(String input) throws Exception
{
    String inputFile = "X:\\tmp\\WORDSNET-20477\\" + input;
    Document baseDoc = new Document(inputFile);
    baseDoc.getMailMerge().setCleanupOptions(MailMergeCleanupOptions.REMOVE_UNUSED_FIELDS);
    baseDoc.getMailMerge().setMergeDuplicateRegions(false);

    mergeDataToDocument(baseDoc, buildUserHeaders(), "userTableHeader");
    mergeDataToDocument(baseDoc, buildUsers(), "usersTable");
    mergeDataToDocument(baseDoc, buildUsers(), "childTable");

    baseDoc.updateFields();//!! added
    baseDoc.save(inputFile + ".out.0.index.with.update.docx");
}

public TestMapDataSource(List<Map<String, Object>> mapList, String tableName)
{
    this.mapList = mapList;
    this.tableName = tableName;
    mRecordIndex = 0;//!! was -1
}

@awais.hafeez
We tried this suggestion. It will not work for us. We have the new issues in case we change mRecordIndex to zero.

Currently we are using examples from Aspose documentation and mRecordIndex is -1 in this example.

The method getChildDataSource will be called if we remove “IF” condition. getChildDataSource is called inside this encrypted class zzZH7 → zz03.zz6(var1) → this.zzXV(0, 1) → getChildDataSource. We are not sure if it help because we have only encrypted classes but if we have IF condition, the method getChildDataSource will not be called inside this.zzXV(0, 1).

@amitpatelbnft,

We have logged these details in our issue tracking system. We will inform you via this forum thread as soon as this issue will get resolved in future or any more updates may be available. We apologize for any inconvenience.

@awais.hafeez Do you have ETA on this? Thanks!

@amitpatelbnft,

WORDSNET-20477 is currently ‘in analysis’ phase and there is no ETA available at the moment. We may be able to calculate and share the ETA (time frame) with you after completing the analysis of this issue. Sorry for the inconvenience.

@awais.hafeez Any new update on this one yet? Thanks!

@amitpatelbnft,

I am afraid, WORDSNET-20477 is not resolved yet and there is no further news about this issue i.e. the issue is still “in analysis” phase. We will inform you here when this issue will get resolved in future or any more updates may be available. We apologize for the inconvenience.

@awais.hafeez any new update on this issue? Thanks!

@amitpatelbnft,

Unfortunately, your issue is still unresolved. We have not completed the analysis of this issue yet. We will keep you posted here on any further updates and notify you when this will get resolved in future. We apologize for the inconvenience.

@awais.hafeez any new update yet? Thanks!