We are using Aspose Cloud Words to mail merge an invoice. In the invoice we want to mail merge a HYPERLINK field using thirdparty_payment_url. We must use regions to repeat table rows.
It appears as though HYPERLINK with regions enabled does not support a MERGEFIELD value and the field does not merge correctly. The hyperlink works with regions disabled.
It is possible to run 2 mail merge requests on the file with regions disabled then enabled but this is slow.
Please note in the scenario that you have two types of data: normal data and list(region) data. You have two solutions. If you want to keep the existing template and data file, then you need to call the MailMege API twice: once withregions parameter set to false and later updating the output file using withregions parameter set to true.
The second solution is to enclose your data in a parent list(region), update your template accordingly, and call the MailMerge API once with the true value of the withregions parameter.
It seems there were two issues. First, your data has duplicate field names, and the HYPERLINK field in the region has a formatting issue in the template file. I have updated your template and data file, and now the HYPERLINK field is working fine with both true and false values of the ‘withregions’ parameter.
I have compared our XML with the one said to have errors (with a tool) and the only difference I can see is a space at the end of your hyperlink value. Are there further errors?
As per my understanding, there was a duplicate field (thirdparty_payment_url) in your XML data. However, the test-local.xml file seems fine. I used it to merge with my above shared updated template and it seems okay to me. Please check and confirm. If you still face any issues, then please share your expected document along with the sample code. You can create your expected document using MS Word. test-local_output.Docx (57.8 KB)
We’re using aspose-cloud/aspose-words-cloud@22.1 PHP SDK, our code is:
$request = new Requests\ExecuteMailMergeRequest(
$template->get_template_filename(), // name
$data, // mail merge data
null, // options
null, // folder
null, // storage
null, // encoding
null, // password
null, // encrypted_password
true, // regions
null, // mail merge data file
'ContainingFields,EmptyParagraphs,UnusedFields,UnusedRegions', // clean up
null, // use whole paragraph as region
$result_filename // resulting file name
);
Please advise what we’re doing wrong to render an invalid document?
It seems the ContainingFields option is removing the Hyperlink field inside the region. I have logged a ticket (WORDSCLOUD-2511) for further investigation. We will share our findings with you soon.