Free Support Forum - aspose.com

MergeField behavior changed on Aspose.Word Java?

Hi all,

We met a regression issue (Pls confirm) that customer mergefield does not support blank character again:

The problem is that: originally we use Aspose 2.4.1 and we implemented table sort function by our custom mergefield format.
For example : <TableSort:InvoiceItem.Amount>, and this would contains ASC/DESC char while we editing in toggle mode. It should be like {MERGEFIELD TableSort:InvoiceItem.Amount DESC *MERGEFORMAT}

So we were able to control the datasource sort rule by this info because MailMerge.getFieldNames() can return “TableSort:InvoiceItem DESC”.

But after upgrading v13.3, MailMerge.getFieldNames() only return “TableSort:InvoiceItem”, the DESC with blank character are disappeared and not be able to be got.

This impact us a lot since we are heavily using this feature to support more sort fields by comma separated merge fields.(Currently even not work for one field)

Could anyone confirm that this is a Aspose behavior change or regression issue?
And how can I get the sort info “ASC/DESC” in current version?
For example, we can get the mergefield name “InvoiceItem.Amount” , but how can I get the DESC?

Hi Guilin,


Thanks for your inquiry.

Starting from the release of Aspose.Words for .NET 9.2, the public API has undergone some changes. It is not common practice for us to make breaking changes to the API and we try to avoid this whenever possible, but sometimes it is necessary. Your problem does not seem to be a bug or regression in the latest version of Aspose.Words 13.2.0; instead, it seems more like a mishandled case in a very old Aspose.Words 2.4.1 API.

Secondly, you can get the field code of a field by using the following code snippet:
/**
  • Retrieves the field code from a field.

  • @param fieldStart The field start of the field which to gather the field code from.
    */


private static String getFieldCode(FieldStart fieldStart) throws Exception
{
StringBuilder builder = new StringBuilder();

for (Node node = fieldStart; node != null &amp;&amp; node.getNodeType() != NodeType.FIELD_SEPARATOR &amp;&amp;
node.getNodeType() != NodeType.FIELD_END; node = node.nextPreOrder(node.getDocument()))
{
// Use text only of Run nodes to avoid duplication.
if (node.getNodeType() == NodeType.RUN)
builder.append(node.getText());
}
return builder.toString();
}

I hope, this helps.

Best regards,