Conditional blocks processing based on Mail Merge

Hello, I haven’t found any solution of the following problem.

I want to use the conditional merge fields in a different way (not as the one merge field containing if, then and else parts together). For example, I have the following text in Microsoft Word template:

{ MERGEFIELD IF FIELD1 = FIELD2 }
{ MERGEFIELD ELSE }
{ MERGEFIELD END }

Does Aspose.Words have the conditional merge process when IF-block is broken into the parts by separate IF ELSE and END merge fields? If it doesn’t are you planning to add the such feature in the future versions?

Any ideas??

I use Aspose licensed version for my customer and I need your answer ASAP. Why are you silent for several days??

Hi Ann,

Thanks for your inquiry and sorry for the delayed response.

Aspose.Words can perform calculations on MERGEFIELD(s) contained inside an IF field; but, could you please attach your sample documents here for testing? I will investigate the issue on my side and provide you more information.

PS: Perhaps you should adopt the following standard structure in your template document which is fully supported in Aspose.Words too:

{ IF { MERGEFIELD mf1 } = { MERGEFIELD mf2 }

<here is the merge fields, tables, static text generated if condition is false and it shouldn’t be generated if condition is true>

<here is the content - merge fields, tables, images, static text - is generated if condition is true and hidden if condition is false>

}

Best regards,

Hi Awais Hafeez,
Thanks for your answer.

Ok, I’ve prepared the sample of IF fields and results which I had on the test data. As you can see, there is the problem with formatting after Mail Merge - I’ve got chaotic formatting which doesn’t fit the original one. Also I have the other problem - I’ve used one IF field inside the other and Aspose Mail Merge missed and didn’t the merge field ACCOUNT_NAME.

Could you help me with these two problems? Let me know if I have mistakes in the merge fields.

Do you have any ideas?

Hi Ann,

Thanks for the additional information.

Regarding the formatting problem in the first IF field, this seems to be an expected behaviour. To confirm this please open your ‘test.docx’ with Microsoft Word application. Replace the MERGEFIELD in the left side of IF expression with the word ‘GenePoint’ which makes the comparison ‘TRUE’. Then performing an UpdateField operation on IF field resolves it to phrase ‘Hello, GenePoint!’, but the formatting is not preserved by Microsoft Word either.

Secondly, Aspose.Words does not calculate ACCOUNT_NAME field because Aspose.Words doesn’t support updating of nested fields in IF field’s false arguments (IF’s TrueText or FalseText argument, which does not correspond to IF’s comparison result) any more. Moreover, such an argument does not affect IF field’s result; therefore, it is safe and there is nothing to worry about. Simply put, in your case, ACCOUNT_NAME field will only be calculated only if both the comparison expressions are false.

Please let me know if I can be of any further assistance.

Best regards,

Hi Awais Hafeez,

Thank you for your answer.

I’ve resolved the second problem - the left part of IF condition was empty and IF field couldn’t be merged properly.

About the first question - formatting. I’ve confirmed the failure of Word formatting on the test data as you suggested me, you’re right. But could you advise me what should I do? Complex IF merge is a very important feature for me and my client and I must resolve this problem with text formatting.

What’s about implementation of your own IF merge field as several blocks for each part separately? Are you going to include this feature in the future versions of Aspose Words? I mean tables are divided on blocks “table start”, “table content” and “table end” and you successfully merge them using regions. What if you could apply the similar engine for conditional merge, it’s possible? It would be an excellent news for my client.

Hi Ann,

Thanks for the additional information. I am in communication with Aspose.Words’ development team and will update you as soon as I have extra information on this topic.

Best regards,

Hi Ann,

Ann:

About the first question - formatting. I’ve confirmed the failure of Word formatting on the test data as you suggested me, you’re right. But could you advise me what should I do?

To workaround formatting issue, please just remove the MERGEFORMAT switch from the IF field and the formatting of the arguments will be preserved.

Ann:

What’s about implementation of your own IF merge field as several blocks for each part separately? Are you going to include this feature in the future versions of Aspose Words? I mean tables are divided on blocks “table start”, “table content” and “table end” and you successfully merge them using regions. What if you could apply the similar engine for conditional merge, it’s possible? It would be an excellent news for my client.

Regarding ‘Our own IFs’, at the moment we are working on the new version of reporting engine that will be equipped with any syntax we would wish. We can add any tags like if, else, then etc if needed. But, you please provide a rough example of how you would like the template to look like. We will investigate the structure of your custom fields on our end and provide you more information

Best regards,