Integrating Dynamics CRM and Word  

November 2, 2011 · Posted by System Account
0  Comments · Trackback Url

Recently I had a need to create a Microsoft Word document and dynamically populate it from data in CRM. Microsoft Word can be invoked from JavaScript using the ActiveXObject . This first example shows a very basic application of the concept. Create a blank document , add a report title then add some body text. In my application I call the JavaScript from a toolbar button added with the ISV.config file. For more information on adding buttons that call javaScript see Calling JavaScript from Microsoft CRM Toolbar Buttons


// Start a new instance of Microsoft Word


var MsWord = new ActiveXObject("Word.Application");


// Create a new document




//Carriage Return




//Report Name




//Carriage Return


//Carriage Return



//Memo field from CRM containing paragraphs of text




//Show Microsoft Word


MsWord.Visible = true;


//To create a new document using a Microsoft Word Template do this:




//To add text to a specific Microsoft Word form field first create a Word template and add a field to it using the developer toolbar then use this code:

msWord.ActiveDocument.FormFields("Text1").Result = crmForm.all.new_name.value;



Obviously you can take this much further, in my application I use a AJAX call to a web service to get related CRM records. I also lock all the fields so their content can't be modified by the user. What the user can do is add content to the document which may include HTML content. The need to generate a report but then add custom content was the genesis for this feature.

Here's a article about creating fields in Microsoft Word. Click Here


0 Links to this post



      Name *:

      CAPTCHA Image Validation