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

Free Support Forum - aspose.com

Conditional merge field not working properly while using htmlFormat keyword

Conditional statement using IF…ELSE is not working properly if we check the the htmlFormat keyword using not equals operator.
Eg:
{ IF { MERGEFIELD htmlFormatDetails } <> “” " INSIDE IF: {MERGEFIELD htmlFormatDetails } " “INSIDE ELSE: {MERGEFIELD htmlFormatDetails }” }
Here, if the content of the htmlFormatDetails is “ABCD 1234 QWER”, this particular field is returning only the 1234 i.e. the 2nd content of the text.
if the content of the htmlFormatDetails is "1234 QWER ABCD ", this particular field is returning QWER

But if I only put «htmlFormatDetails» i.e. { MERGEFIELD htmlFormatDetails }, all the respective values will be returned.

Also, if I check the conditional statement for the normal keyword (that is without htmlFormat) then it works perfectly.
i.e. { IF { MERGEFIELD details } <> “” " INSIDE IF: {MERGEFIELD htmlFormatDetails } " “INSIDE ELSE: {MERGEFIELD htmlFormatDetails }” }
Here, as were are checking the normal details keyword, it works perfectly.

Also, if I check the conditional statement using other values except the not equals then it works perfectly.
i.e. { IF { MERGEFIELD age } < “18” " INSIDE IF: {MERGEFIELD htmlFormatDetails } " “INSIDE ELSE: {MERGEFIELD htmlFormatDetails }” }
Here, as were are checking the < operator with “18” value, it works perfectly.

The only issue we are facing currently is when the htmlFormatted keyword is checked with not equals to empty.
Note: We are currently using Aspose Word 20.2
Code Snippet:
if ((e.getFieldName())?.startsWith(‘htmlFormat’)) {
if(!e.getFieldValue().equals(’<<’+e.getFieldName()+’>>’)){
mBuilder.moveToMergeField(e.getFieldName());
if(e.getFieldValue()) {
mBuilder.insertHtml((String) e.getFieldValue(),true)
}
}
}

Could you please analyze?

@sdevbhandari

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

  • Your input Word document.
  • Please attach the output Word file that shows the undesired behavior.
  • Please attach the expected output Word file that shows the desired behavior.
  • Please create a simple Java application ( source code without compilation errors ) that helps us to reproduce your problem on our end and attach it here for testing.

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

PS: To attach these resources, please zip and upload them.

Files.zip (97.5 KB)
Please find the attached files where I have attached the template, output of that template and the expected output file.

The above issue is working fine for the normal text but is giving issue for htmlFormat Keyword while checking <> “”. The code snippet where we are checking the keyword starting from “htmlFormat” is:
if ((e.getFieldName())?.startsWith(‘htmlFormat’)) {
if(!e.getFieldValue().equals(’<<’+e.getFieldName()+’>>’)){
mBuilder.moveToMergeField(e.getFieldName());
if(e.getFieldValue()) {
mBuilder.insertHtml((String) e.getFieldValue(),true)
}
}
}

@sdevbhandari

Thanks for sharing the documents. Please also create a simple Java application ( source code without compilation errors ) that helps us to reproduce your problem on our end and attach it here for testing.

Thanks for your cooperation.