Freigeben über


Add a contact in Outlook from a CRM contact form

Here is a sample code to add a button into CRM contact form which will push contacts in Outlook. JavaScript code inside this button takes contact info and adds it directly in Outlook. We've done it for demonstration, this is a base to improve. Fullname field is the index to check duplicate contacts

clip_image001

All is done in the ISV.config file.

The source code has been done to work with Outlook 2007 and CRM 4.0.

 

 

 

 

Two Prerequisites: Once an Outlook 2007 application is installed on the system and the security setting is done as per above, we are ready to use this feature

  • Since we need to create Outlook contact on the client-side, we will be using an ActiveX object. Thus, we need to enable the setting to allow ActiveX scripts, as shown below (found under Security Settings of Internet Options):

clip_image001[6]

For demonstration, I prefer set my CRM Web Site as 'trusted sites'

 

 

 

 

 

 

 

 

and 'Enable' - Initialize and script ActiveX controls not marked as safe for scripting.

image

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  • Outlook 2007 installed on client machines

The ISV Config Part :

<ImportExportXml version="4.0.0.0" languagecode="1036" generatedBy="OnPremise">   <Entities>   </Entities>   <Roles>   </Roles>   <Workflows>   </Workflows>   <IsvConfig>     <configuration version="3.0.0000.0">       <Root />       <Entities>         <Entity name="contact">           <ToolBar ValidForCreate="0" ValidForUpdate="1">             <Button JavaScript="                     var outlookApp = new ActiveXObject('Outlook.Application');             var nameSpace = outlookApp.getNameSpace('MAPI');             var contactFolder = nameSpace.getDefaultFolder(10);             var firstname = '';             var lastname = '';             var fullname = '';             if(crmForm.all.firstname != null &amp;&amp; crmForm.all.firstname.DataValue != null)             {                   firstname = crmForm.all.firstname.DataValue;                   fullname = firstname;              }             if(crmForm.all.lastname != null &amp;&amp; crmForm.all.lastname.DataValue != null)             {                   lastname = crmForm.all.lastname.DataValue;                   if(fullname != '')                     fullname += ' ';                   fullname += lastname;              }

            if (fullname != '' &amp;&amp; contactFolder.Items.Find(&quot;[FullName] = '&quot; + fullname + &quot;'&quot;) == null) {                 var contact = outlookApp.CreateItem(2);                 contact.FullName = fullname;                 contact.FirstName = firstname;                 contact.LastName = lastname;                 if(crmForm.all.emailaddress1 != null &amp;&amp; crmForm.all.emailaddress1.DataValue != null)                   contact.Email1Address = crmForm.all.emailaddress1.DataValue;                 var ar = new Array();                 if(crmForm.all.parentcustomerid != null &amp;&amp; crmForm.all.parentcustomerid.DataValue != null)                 {                    ar = crmForm.all.parentcustomerid.DataValue;                    contact.CompanyName = ar[0].name;                 }                 if(crmForm.all.mobilephone != null &amp;&amp; crmForm.all.mobilephone.DataValue != null)                   contact.MobileTelephoneNumber = crmForm.all.mobilephone.DataValue;                 if(crmForm.all.telephone1 != null &amp;&amp; crmForm.all.telephone1.DataValue != null)                   contact.BusinessTelephoneNumber = crmForm.all.telephone1.DataValue;                 if(crmForm.all.jobtitle != null &amp;&amp; crmForm.all.jobtitle.DataValue != null)                   contact.JobTitle = crmForm.all.jobtitle.DataValue;                 if(crmForm.all.fax != null &amp;&amp; crmForm.all.fax.DataValue != null)                   contact.BusinessFaxNumber = crmForm.all.fax.DataValue;                 if(crmForm.all.address1_city != null &amp;&amp; crmForm.all.address1_city.DataValue != null)                   contact.BusinessAddressCity = crmForm.all.address1_city.DataValue;                 if(crmForm.all.address1_stateorprovince != null &amp;&amp; crmForm.all.address1_stateorprovince.DataValue != null)                   contact.BusinessAddressState = crmForm.all.address1_stateorprovince.DataValue;                 if(crmForm.all.address1_postalcode != null &amp;&amp; crmForm.all.address1_postalcode.DataValue != null)                   contact.BusinessAddressPostalCode = crmForm.all.address1_postalcode.DataValue;                 if(crmForm.all.address1_country != null &amp;&amp; crmForm.all.address1_country.DataValue != null)                   contact.BusinessAddressCountry = crmForm.all.address1_country.DataValue;                 var address = '';                 if(crmForm.all.address1_line1 != null &amp;&amp; crmForm.all.address1_line1.DataValue != null)                   address += crmForm.all.address1_line1.DataValue;                 if(crmForm.all.address1_line2 != null &amp;&amp; crmForm.all.address1_line2.DataValue != null)                   address += ' ' + crmForm.all.address1_line2.DataValue;                 if(crmForm.all.address1_line3 != null &amp;&amp; crmForm.all.address1_line3.DataValue != null)                   address += ' ' + crmForm.all.address1_line3.DataValue;                 contact.BusinessAddressStreet = address;

                contact.Save();                 alert('Contact creation succeed');             } else {                 alert('already exist');             }                     " Client="Web">               <Titles>                 <Title LCID="1036" Text="Add contact in Outlook" />               </Titles>               <ToolTips>                 <ToolTip LCID="1036" Text="Add contact in Outlook" />               </ToolTips>             </Button>           </ToolBar>         </Entity>       </Entities>     </configuration>   </IsvConfig>   <EntityMaps />   <EntityRelationships />   <Languages>     <Language>1036</Language>   </Languages> </ImportExportXml>

Hope this helps

PAF

Comments

  • Anonymous
    March 20, 2014
    Hai..                How can we access local outlook in serverside(for importing Outlook contacts ) and also provide its code in javascript....... My mail is :sivasmily06@gmail.com