Skip to content
This repository has been archived by the owner on Apr 16, 2022. It is now read-only.

How to manipulate a if conditional mail merge field in docx-mailmerge #78

Open
schinnaswamy opened this issue May 12, 2020 · 4 comments

Comments

@schinnaswamy
Copy link

We want to show certain text in the word document based on mail merge field conditions. Basically trying to make use of if conditional merge fields.

Let say we have different annexure documents attached with the main document. The annexures vary based on the client's terms and conditions.

For Example:

If a client's document has 2 annexures in the main document text should load with dynamic text like

This agreement contains the following annexures
Annexure A
Annexure B

If a client's document has 4 annexures in the main document text should load with dynamic text like

This agreement contains the following annexures
Annexure A
Annexure B
Annexure C
Annexure D

I am trying to add the if conditional merge field in the template as follows
======== Doc template =======

This agreement contains the following annexures

{ IF {MERGEFIELD AnnexA} - "Y" "Annexure A" ""}
{ IF {MERGEFIELD AnnexB} - "Y" "Annexure B" ""}
{ IF {MERGEFIELD AnnexC} - "Y" "Annexure C" ""}
{ IF {MERGEFIELD AnnexD} - "Y" "Annexure D" ""}

Expected Behavior

The AnnexA, AnnexB, AnnexC & AnnexD should be returned when getMergeFields() method is invoked. Instead, the method doesn't recognize if conditional mail merge fields

Please share your thoughts

@sujayramaiah
Copy link

Hi,

We are also experiencing the same issue.
The IF condition does not seem to get evaluated.
Is this feature not supported? Is there any workaround?
Please advise.

Thanks,
Sujay

@diegolimaf
Copy link

Hi,

I am facing the same issue now.
I want to include some IF conditions in my template but it does not work as expected.
Did you find any solution?

Thanks

@sujayramaiah
Copy link

Hi @diegolimaf,

We came up with a workaround. Basically reformatted the data to handle the conditional structure outside of mail merge and then fed it into the mail merge. Within the template there will be both form field for condition A or B in the same block. If A has a value, B will not have a value in the restructured data we are feeling in.

Please let me know if you need any further information.

Thanks,
Sujay

@O7lo
Copy link

O7lo commented Mar 22, 2021

hi @sujayramaiah ,

i am also facing this issue right now and i would love to have more information about your workaround. This could be really helpfull to me.

thanks for your help

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants