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

Free Support Forum - aspose.com

If condition doesn't work as before

Hi Supports,

I used Aspose.Words 15.2.0 to generate PDF which worked well with IF condition. But After I migrated to Aspose.Words 17.4.0, the If condition can’t be merged correctly.

The following is the IF condition expression in my template,

{ IF { MERGEFIELD Account.Currency } = USD { MERGEFIELD Invoice.InvoiceNumber } { MERGEFIELD Account.Currency } }

To make the process more clear, I saved the result as DOC.

So with 15.2.0, I got the following result:

Invoice.InvoiceNumber, Account.Currency were not merged with 17.4.0.

Could you please have a look and fix this issue?

The following is the test code to reproduce this issue.

public class IFTest
{
    public static void main(String[] args) throws Exception
    {
        Document doc = new Document("Account.Currency\_showMergeField\_unmatch\_template.doc");
        doc.getMailMerge().execute(getDatasourceOne()); //Merge Invoice properties
        doc.getMailMerge().execute(getDatasourceTwo()); //Merge Account properties
        doc.save("IFCondition.doc", SaveFormat.DOC);
//doc.save"IFCondition.pdf", SaveFormat.PDF);
        System.out.println("done.");
    }

    public static IMailMergeDataSource getDatasourceOne()
    {
        return new IMailMergeDataSource() {
            boolean hasNext = true;
            public String getTableName() throws Exception {
                return "Invoice";
            }

            public boolean moveNext() throws Exception {
                if (hasNext)
                {
                    hasNext = !hasNext;
                    return true;
                }
                else
                {
                    return false;
                }
            }

            public boolean getValue(String paramString, Object[] paramArrayOfObject) throws Exception {
                if (paramString.contains("Number"))
                {
                    paramArrayOfObject[0] = "INV-000001";
                }
                else
                {
                    return false;
                }
                return true;
            }

            public IMailMergeDataSource getChildDataSource(String paramString) throws Exception {
                return null;
            }

        };

    }

    public static IMailMergeDataSource getDatasourceTwo()
    {
        return new IMailMergeDataSource() {
            boolean hasNext = true;
            public String getTableName() throws Exception {
                return "Account";
            }
            public boolean moveNext() throws Exception {
                if (hasNext)
                {
                    hasNext = !hasNext;
                    return true;
                }
                else
                {
                    return false;
                }
            }

            public boolean getValue(String paramString, Object[] paramArrayOfObject) throws Exception {
                if (paramString.contains("Currency"))
                {
                    paramArrayOfObject[0] = "USD";
                }
                else
                {
                    return false;
                }
                return true;
            }

            public IMailMergeDataSource getChildDataSource(String paramString) throws Exception {
                return null;
            }
        };
    }
}

Hi there,

Thanks for your inquiry. We have tested the scenario and noticed the reported issue, so logged a ticket WORDSJAVA-1557 in our issue tracking system for further investigation and rectification. We will notify you as soon as it is resolved.

We are sorry for the inconvenience.

Best Regards,

Hi Tilal,

Thanks for the quick response.

We are trying to upgrade the Aspose.words from 15.2.0 to 17.4.0 which fixed the issue we reported before.(Generated document contains data of another document in multi-threading environment). Currently, this issue became a blocker of our upgrading. We have a lot of customers who are using IF condition expression in their PDF template, it is a big risk for us to upgrade without fixing this issue. This issue is very critical for us as well as for you, IF condition is a very common feature of Aspose mail merge, could you give higher priority to fix this issue.

Thanks

Tony

Hi Tony,

Thanks for your feedback. Our product team is already treating above issue with high priority. However, we have also shared your concern with our team. We will keep you updated about the issue resolution progress within this forum thread.

Thanks for your patience and cooperation.

Best Regards,

Hi Tony,

Thanks for your patience. We have investigated the issue and found it is not a bug. Aspose.Words processes only one part of the IF field depending on the condition’s result just like MS Word does. You are performing Mail Merge in two steps:

  1. merge the Invoice.InvoiceNumber field
  2. merge the Account.Currency field

At the first step the Invoice.InvoiceNumber mergefield is not merged because parent IF field condition is false. At the second step second Account.Currency mergefield is not merged because parent IF field condition is true.

To resolve this issue, you should combine datasources and perform Mail Merge in single step.

Best Regards,

Hi Tilal

Thanks for the reply.

As I said, it worked well when we use Aspose.words 15.2.0, but it failed with Aspose.words 17.4.0. When did you make this change?

It is a huge effort for us to combine datasources, because we have tens of datasources. Do you have any way to make the IF condition of 17.4.0 work in the same way as 15.2.0? For example, making some configurations.

BTW, does Aspose.words only work with one datasource when merging with one template? how to support multiple datasources?

Thanks

Tony

Hi Tony,

Thanks for your inquiry. We have intentionally changed Aspose.Words behavior in Aspose.Words for .NET 15.12 to mimic MS Word.

Aspose.Words Mail Merge feature does not support multiple data sources for a template. However you may use LINQ reporting feature of Aspose.Words for multiple data sources.

Best Regards,

Hi Tilal,

Can you deliver a maintainance release to resolve the 15.2.0 issue we reported before? (Generated document contains data of another document in multi-threading environment). Upgrading to 17.4.0 need big effort for us because our application was built based on the behavior of 15.2.0.

Thanks

Tony

Hi Tony,

Thanks for your inquiry. I am afraid we cannot provide the hotfix/maintenance release of old versions as we maintain a single code base of Aspose APIs. All the fixes and new features/enhancements are implemented in latest version of DLL. You need to upgrade to latest version to get fix of your reported issue.

We are sorry for the inconvenience caused.

Best regards,