function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
brailmbrailm 

Mailmerge and {IF}

Has anyone been able to use the {IF} in Word's mailmerge to conditionally include text based on a value returned from Salesforce?
 
For example:
{ IF «OPPORTUNITY_NUM_SVCS_DEFINED» <> "1" "Some conditional text." " " }
 
The example from Microsoft shows:
{ IF {MERGEFIELD Country \* Caps } <> "United Kingdom" "We offer special rates on travel to the British Isles." " " }
 
Which I have successfully used before.
 
gsickalgsickal
Yes and it works great.  You can use Salesforce's office toolkit and the Office Edition which includes a Word addin to add merge fields to a Word document.  Just insert these fields inside a conditional expression using word mergefields and point it to a valid datasource when you do the actual merge.
JakesterJakester
Would you be so kind as to provide a concrete example? I tried to do this and wasn't sucessful. I'd have many uses for it, but one way I would love to use this would be to replace the blanks in Salesforce which appear in the merge letter as a bunch of underscores with a true blank.

Thanks!

-Jake
gsickalgsickal
Unfortunately to do that (replace underscores with blanks) you'd have to write your own merge handler.  Actually I was wrong before, the salesforce mail merge will not work for what you want since it does not call Word's builtin merge method which would do the right thing, but basically just searches and replaces the merge fields with their values... You will have to write your own merge handler in this case... Take a look at Print Anything on the appexchange...
JakesterJakester

Thanks so much for your prompt reply and the Print Anything suggestion - this looks like it might do the trick! I also signed up for a trial of Conga Merge, which is very slick and pretty cheap.

-Jake

brailmbrailm

Here's how I solved the problem.

Tag the data that want to base the condition on as a named bookmark (Insert | Bookmark). If you don't want to display that value, hide it using format, font, hidden. You can then refer to the bookmarked field in the merge condition. Here's a sample:

{ ·IF·booking_system·=·"OSC"·"OSC"·"IBIS"· \*·MERGEFORMAT··}¶

booking_system is a bookmark containing the salesforce data field.

Works like a charm.

JakesterJakester

Wow - that sounds like a really great solution, but I'm having trouble getting it to work with my situation. Here's the deal: I've got a field called PO_Number, and if it's blank, I'd like to suppress it instead of showing a bunch of underscores... however, if it's not blank I'd like to show the PO_Number.

So, I added the PO_Number field, associated it with a bookmark called PO, and then I tried the following IF field:

Code:

IF PO = "_____" "" PO  \* MERGEFORMAT 


 
If the PO_Number is empty it displays "PO" instead of nothing.

brailmbrailm
Blank should "" not "____".
JakesterJakester
But that's what Salesforce returns on blanks: a series of underscores. Even that was wrong, according to the IF statement I should have either gotten nothing or the actual PO number. Instead, I got the text "PO".
brailmbrailm
Can you send an example of your merge code?
JakesterJakester
I'd be glad to - it's very kind of you to continue to keep responding! I posted it above in a previous message - is there some other way I can send it? I don't see a way to attach an entire merge document here, so I uploaded it here: http://download.yousendit.com/C8ED31D2276F68F1
brailmbrailm
Your Code {·IF·PO·=·"________"·""·PO·· \* MERGEFORMAT   \*MERGEFORMAT}
 
Try this {·IF·PO·=·"_______"·""·PO·· \* MERGEFORMAT }
 
Are you sure about the number of underscores? You have 9, it should be 8.
 
I am checked what happens in mine when the field is null (I don't have that problem as I am testing a picklist value from a required field). Test worked with this code:
 
{·IF· address1 =·" ________"· " "· "test"· \*·MERGEFORMAT }
 
 
 
JakesterJakester
That change didn't help. It is indeed 8 underscores which is what I have been using. Did you download the word file that I linked to you?
brailmbrailm

Yes I did. But we don't use products and don't have your configuration so I could not test it locally. The way I tested was to add the logic to my template. I'm working with you because I expect to have to deliver the same requirement soon.

I would be willing to use GoToMeeting to resolve this.

JakesterJakester
That'd be great! You can reach me at xxx xxx-xxxx. Let me know once you have that number written down and I'll edit it out of this post.
 
Best,
 
-Jake

Message Edited by Jakester on 11-16-2007 05:55 PM

brailmbrailm
got it.
JakesterJakester
Great - I look forward to talking with you on Monday. I'm on Pacific Time and will be in by 8am, but whenever's good for you is fine by me.
LpitriLpitri

Brian,

I am not a developer. Can you help me with some clear steps as to how to get rid of the Blanks when doing a mail merge?

I am trying to merge a salesforce <<account_name>> but don't want the ____ (blanks).

It looked like you solved the problem. But I don't even understand how to setup the book mark you are referring and what you mean by tagging the data.

Any help is greatly appreciated.

Luis

brailmbrailm

Luis,

Look at my earlier messages. I'd like to help you, but could you start with MS Word help on setting bookmarks? This is base Word functionality. You might also read up on Mail Merge in general. IF you still have issues after referring to these resources, I'll help.

Also, I'm BRAILM, not Brian. It took a while to figure out you addressed this to me.

SunilSunil

Hi Brailm,

I tried mail merge with IF condition as you suggested using bookmark. Here is the line of code I have: -

{ IF.Spouse_Name.=."N/A"."No Spouse"."Spouse".}

Spouse_Name is a bookmark containing the salesforce data field - [MERGEFIELD ACCOUNT_SPOUSE_S_NAME].

When I generate the file, I get { IF.Spouse_Name.=."N/A"."No Spouse"."Spouse".} in the file. It is not executing the code.

Can you tell me if I am missing anything?

Thanks

Sunil




Message Edited by Sunil on 06-13-2008 06:11 AM
damienmagnandamienmagnan
Hi everyone,

I "up" this topic because I'm working on Word document with mail merge but I don't understand how {IF} works.
I want to test the civility of a person to modify my document like this :

{if {mergefi... contact_salutation \* mergefi...}= "Mister""his""her")}

The result is an error like "the test condition isn't found".
Please, can you explain to me how use this function? Also you speak about "bookmark", can you detail more?

Thank you.

Damien.
JakesterJakester
I struggled a lot with this, too. I'd highly recommend contacting the guys at www.appextremes.com/ - they have a fantastic product is infinitely more customizable and user-friendly than Salesforce's built-in tools and they are extremely affordable. Plus, any time I call I get a real person to pick up almost immediately, and it's usually one of the main developers of the app! They can walk you through almost anything, and provide you with a 100+ page manual which is actually well-written with tons of examples. Highly recommended.
damienmagnandamienmagnan
Thank you for your response but unfortunately I can't get this application (Conga Merge) :robotsad:. I must make my own Word document but I don't know if it's possible to make this with function.

If you have any exemple, I'm listening (reading :robothappy:).
brailmbrailm
I'm trying to meet a project deadline. So I can't reply in detail now. We are successfully using the solution in production. I'll get back to you later.
JakesterJakester
Brailm is a super-nice guy and has helped me with some tricky mailmerge stuff before in the past - thanks again, Brailm!
damienmagnandamienmagnan
I'm sure that this man can help me. :robotwink: I wait for your return but if anyone have the solution for the bookmark using...

Good luck for your project brailm.
thomasGEthomasGE

Hi we've got a similar problem.

 

 

 

I put a named bookmark 'Salut2' into a word template and assigned the mergefield contact_salutation to it. Using a compare like compare Salut2 = Mr. delivers a 0 or 1 if Mr. is true. So far it seems to work.

Using the mix of IF and OR condition does not work. My code was:

{ IF { = OR ({ COMPARE Salut2 = Mr. } , { COMPARE Salut2 = Mrs. }) = 1 "do something" "do something else"}}.

Putting the bookmark into curly brackets did not work. Using a semicolon instead of a comma between the compares did not work either. More or less blanks in between did not work. What is the mistake I make?

The field contact_salutation is filled properly from salesforce. I also tried with contact_salutation as a mergefield in the compare. This did not succeed.

Do you have any idea on how to solve that? I would be very glad to get help around that.... Thanks in advance....

Cheers Thomas