Insert space before and after comparison operator in an IF-Then condition in word Docx document using C# and after adding MailMerge.CleanupOptions I unable to get doc.Range.Fields data

I use an if-then condition in a template. To handle case sensitive, I have converted data in upper case

Problem:

  1. If there is no space before or after comparison operator, Aspose.Words does not evaluate the condition correctly. In addition, only the part up to the space is output.

How can I programmatically add the space before and after comparison operator?

  1. After adding MailMerge.CleanupOptions I unable to get data of doc.Range.Fields

How can I get doc.Range.Fields data after adding MailMerge.CleanupOptions?

@mugdhak

  1. Could you please attach a sample temple that demonstrates the problem? We will check the issue and provide you more information.

  2. After executing mail merge. merge fields are replaced with text. So the fields are no longer listed in Range.Fields. This is the expected behavior and this is how MS Word executes mail merge.

I have attached here sample application. CaseSensitivity.zip (72.6 KB)

@mugdhak Thank you for additional information. If your data contains whitespaces you should surround data with quotes. Your field code should look like this:
{ IF "{ MERGEFIELD Name }" ="ABC" "True Name" "False Name" }
Also, you can set \* Upper switch in your merge field to convert it to upper case upon executing mail merge. So you can simply use the following field code and do not do any postprocessing of IF fields in the code:
{ IF "{ MERGEFIELD Name \* Upper }" ="ABC" "True Name" "False Name" }

Thanks for response.

If right expression in lower case in that case to handle case sensitive, I need to convert into uppercase using IF fields

{ IF "{ MERGEFIELD Name \* Upper }" ="abc" "True Name" "False Name" }

Above scenario output is like this =“ABC” .

If the both expression are correct then I want output as True Name else False Name

For above scenario I want output as True Name

Can you please suggest me, regarding same.

@mugdhak The problem occurs because changing the FieldIf.RightExpression breaks the field.
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): WORDSNET-25030

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

I would suggest you to avoid IF field postprocessing in the code and simply properly setup them in the template. If your right expression is upper case then using:
{ IF "{ MERGEFIELD Name \* Upper }" ="ABC" "True Name" "False Name" }
If the right expression is lower case, the using this:
{ IF "{ MERGEFIELD Name \* Lower }" ="abc" "True Name" "False Name" }

Thanks for response.

Equal condition in IF was case sensitive.

It would be difficult to assume what would be case of left and right expression in templates.

So to handle case sensitive, I need to use IF field postprocessing. If I didn’t used IF field postprocessing then all conditions become false.
I converted left and right expression in uppercase using IF fields.

@mugdhak I understand your requirement. But due to the defect WORDSNET-25030, your workaround does not work.
When you setup your template you can see whether the constant part of the condition is upper or lower case and add the appropriate switch to the merge field. Of course if you have control over the template creation process.