Rename Mergefield within IF

Hi,

I have the following problem:

I have old word documents, containing mergefields and If’s.
For instance:

MERGEFIELD M_1
MERGEFIELD 2
{ IF { MERGEFIELD M_3 } = “This is Three” “{MERGEFIELD “M_4”}” “” }

Some of the mergefields are named M_, others are just .

What I want is to change the MERGEFIELD 2 to MERGEFIELD M_2. This is no problem using a variant of following code.

Variant :

Integer getal = null;
try{getal = Integer.parseInt(mergeField.getName());}catch(NumberFormatException ex){}
if(getal != null)
mergeField.setName(“M_” + getal.toString());

I expected this to only find the MERGEFIELD 2… it however finds the MERGEFIELD M_3 and MERGEFIELD M_4 as well. Because they are inside the IF, the mergeField.getName() returns 3 and 4, instead of M_3 and M_4. Does anyone have any suggestions on how to overcome this problem?

Thanks!

Kind Regards

Matthias

Never mind my retardness…

Before I tried the renaming, I just tried mapping the fields. This didn’t seem to work.
Now I realise I made a typo there… Works perfectly now, no need to rename the fields.

Sorry!

Greetings

Matthias

Hello

It is perfect, that you already fond the reason of the problem. Please let me know in case of any issues, I will be glad to help you.

Best regards,