We help IT Professionals succeed at work.

Conditional Text in Word with XML data source

Laurence Martin
I have a potential client that is using an ERP system called Priority which produces various documents such as invoices using a Word template with mapped XML fields.

Sometimes they will produce a single document, sometimes it is a batch.

They want the document to say different things depending on the data.

If this were a Word mail merge I would use a If..Then..Else field in the mail merge, but they tell me that isn't working.  I guess that is because they aren't running a Word merge.

Can you use IF fields in this XML situation, if so how?
Watch Question

John KorchokProduction Manager

The answer will depend on how Priority operates. Here's their contact page, where you can request a demo and ask questions: Priority Contact Page
Laurence MartinTraining Director


OK, let's forget about Priority for a moment.  I'd like to learn more about IF fields.

How do they work when it's not a mailmerge?

The Microsoft website just says {If order>100 "truetext" "falsetext"}.  What is "Order"? A bookmark?

If I want to reference a Content Control, how do I do that?
Production Manager
In your example order will be a variable that contains a number.

To reference Content Controls, you usually loop through the collection to find the one that meets your criteria. Unfortunately, a Content Control doesn't have a unique identifier. Often you can reference a Content Control by its Title or its Tag, but neither of those are necessarily unique. Duplicates can exist. This Stack Overflow post has 2 workable answers:Get ContentControl by title (or tag)

Here is Microsoft's reference page on Working with Content Controls:
Laurence MartinTraining Director


Thanks John,

I thought that Content Controls would be difficult.

My question was all about the field code, without using VBA,

We are waiting to see what Priority say.

I hope you are staying safe and well.