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

Free Support Forum - aspose.com

Do not include data on generated word file when if condition is false

Hi,


I am using REST api for salesforce to generate word document.

On word template my merge field syntax is as follows,

{{#foreach OrderDetailList}}

{if {MERGEFIELD ProductLineName}=“ABC” "

{MERGEFIELD TableStart:OrderDetailLineList}

{MERGEFIELD ProductName}

{MERGEFIELD TableEnd:OrderDetailLineList}

" “”}

{{#foreach OrderDetailList}}


I am passing ProductLineName as “PQR” to template while generating word file. So the If condition will not satisfy and will display as blank.

when word file is generated, it is keeping false region that is OrderDetailLineList data in hidden format. I don’t want to include this data to generated file as condiion is false,still it is adding . What to do in this case??

I am passing “&cleanup=EmptyParagraphs,UnusedRegions,UnusedFields,ContainingFields” parameter in http post request while generating word file. but still it is not working !!

Can any one guide me on it ??

Hi Sonal,

Thanks for your inquiry. It would be great if you please share following detail for investigation purposes. We will investigate the issue on our side and provide you more information.


  • Please attach your input Word document.
  • Please attach the output Word file that shows the undesired behavior.
  • Please
    attach the XML data source.

Hi,

Thank you for your quick response. I have created dummy example for you.

I have attached xml , Template and generated file !!

Steps to generate issue,
1. Open DocumentBuilderAndSave.docx (ie. generated file)
2. Select all content.
3. Right click and click on “Toggle field codes”
as if condition is false it should not add false content block on the document !! but it is adding !!

Hi,

I tried above in .NET. In .NET you provided a method called ,

FieldsHelper.ConvertFieldsToStaticText(doc, FieldType.FieldIf);

which is removing static If from document. So I want same for REST API.

What should I use in REST API for same functionality ??

Hi Sonal,

Thanks for sharing the detail. We have tested the scenario and have managed to reproduce the same issue at our side. The cleanup options do not remove the IF field codes. For the sake of correction, we have logged this problem in our issue tracking system as SAASWORDS-260. You will be notified via this forum thread once this issue is resolved. We apologize for your inconvenience.

Sonal.g:
as if condition is false it should not add false content block on the document !! but it is adding !!
The IF field’s false contents “false condition” should be visible in output document. This is expected behavior. The contents of IF field are shown based on condition.

The issue you have found earlier (SAASWORDS-260) has been fixed in this Aspose.Words for Cloud update .