lazarus
lazarus

Reputation: 2017

CRM 2011: How to programmatic create document using mail merge template?

I created some mail merge template. It should create some email and sent to some contact. Template is using 'contact' entity.

How to create document from code using that template? And, for example, send mail to specified contact.

Upvotes: 1

Views: 3150

Answers (2)

Dead.Rabit
Dead.Rabit

Reputation: 1975

MailMerge in CRM is a bit of a funny one. You upload a Word template (using a wizard) to create the MailMergeTemplate entity, during this process CRM will then inject a little macro into the document.

Downloading the document merged with data, actually just pushes the data into an HTML table that is placed as a comment in the word document, when you open the document (and go through the Word Mail-merge wizard again) the data is moved by the macro from the comment into the form fields.

So if you wan't to complete your mailmerge, you need both the template (stored as an xml blob in CRM), at this point I chose to insert the data manually (so I can't help you getting the sdk to inject the HTML table) by manually creating my own html table of data in a separate file (you need the entity data stored against display name and the calling user entity also against display name but prefixed with User_), you can then simply use the Word SDK to start and finish the mail merge in an automated way.

FYI the technique I used isn't supported by microsoft because Word churns out too many error messages to be automated so I got around this by installing a ClickOnce app on clients that did the merge so there would always be a user present. If you wan't to merge on a server, prepare to wage battle with DCOM also.

Upvotes: 2

Christian Payne
Christian Payne

Reputation: 7169

I've come across this a few times. When you say document, do you mean a Word attachment?

If so, this isn't a CRM thing, its a Word thing.

Similar Stackoverflow questions are a good place to start.

To get it working is complicated. Once you have populated your Word document, you have to get it back into CRM. It's messy...

Upvotes: 0

Related Questions