RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Using Microsoft Dynamics CRM 4.0 as a Development Platform : Page 3

Microsoft Dynamics CRM 4.0 provides a robust development platform for server-side developers. Find out how web services exposed by the MS CRM SDK can be used to build line-of-business custom solutions on CRM data.


Creating MS CRM Entity Web Parts

Before creating the entity web parts you need to create the ASP.NET personalization database that stores the web part configuration information. At the Visual Studio command prompt, execute the aspnet_regsql command. Follow the steps in the wizard to create a personalization database.

With the personalization database in place, you're ready to create the web parts. First, note the web parts folder in the CRMWebParts application, which has two user controls named ContactWebPart and AccountWebPart. The user controls inherit from the WebPartBase class, which implements the IWebPart interface. The following code shows a sample property exposed to the editor part that a user can set when the site is running in edit mode:

   WebBrowsable, WebDisplayName("Account Field 1"),
   WebDescription("Enter the Field Name")]
public string Field1
   get { return _field1; }
   set { _field1 = value; }
Figure 2. Displaying Web Part Properties in the Editor Zone: Specify the entity properties that you want to display in the web part.

The WebBrowsable attribute allows the property to be displayed in the property editor. In the Default.aspx page add three web part zones, and then add the ContactWebPart and AccountWebPart user controls to the left and center zone templates respectively. Run the site in edit mode and click edit on the web part menu to display the property editor (see Figure 2).

In the editor zone, you can specify which entity properties that you want the application to display to web part users. This example supports only three properties per web part, but you can expose more fields to display additional entity properties. You can find a list of entity property names in the SampleProperties.txt file. The configuration information gets saved in the personalization database so it will be available the next time you run the page. Add the following code in the Default.aspx page Page_Load event handler to populate the entity web parts with the data retrieved from the CrmWebservice:

   CrmSdk.contact entity = 
      "contact", new Guid(Request.QueryString["contactId"])) 
      as CrmSdk.contact;
   CrmSdk.account linkEntity = CRMHelper.GetRecordByEntityId(
      "account", "contact", "accountid", "contactid", 
      new Guid(Request.QueryString["contactId"])) 
      as CrmSdk.account;

The preceding code accepts a contactId as a query string, and then calls the CRMHelper methods to fetch the contact and account information from MS CRM. It then populates the web parts with the retrieved data using the SetFieldValues method exposed by the AccountWebPart and ContactWebPart user controls. The SetFieldValues method assigns values to the configured properties by dynamically looking for the property information in the BusinessEntity.

The CRMWebParts web application contains a SearchContacts.aspx page that displays all the contacts available in your organization in a DataList. Double-clicking on a contact row redirects to the Default.aspx page with the contactId of the selected contact appended as a query string.

The next step show how external applications can consume MS CRM Data. To demonstrate this, the weather web part in the CRMWebParts web application uses the zip code for a contact or account to display the weather for that location.

Place the WeatherWebPart user control in the right web part zone of the Default.aspx page. The page calls the SetZipCode method, which sets the location of the Weather control based on the zip code returned by the entity record. Figure 3 shows how the default page looks after you double-click on a contact record in the SearchContacts page.

Figure 3. Zip Code-Based Weather: Double-clicking a contact in the SearchContacts page displays a weather report based on that entity record's location.
Author's Note: You must add a reference to the anrControls.Weather.dll assembly for the weather control to work. The weather control itself was written by Milan Negovan, and you can find detailed information about it in his Weather Custom Server Control article.

As you can see, the ability to call MS CRM web services opens up enormous opportunities for using it as a development platform. This example showed how to build a simple configurable dashboard view on Entity data using CrmService, but you could easily extend the application by providing data-editing capabilities so users could access and manipulate MS CRM entity metadata. It's worth noting that the CrmService is also available in offline mode, so you can build applications that support offline scenarios.

For more information on using MS CRM as a development platform, see the "Developing Custom Solutions" section of the Microsoft Dynamics CRM 4.0 SDK. Visit the Microsoft Dynamics CRM Home page for updated information on MS CRM. Finally, you can find more information about the weather service here.

Sandeep Chanda has more than five years of experience in several Microsoft technologies. He currently works for Neudesic, a Microsoft National Systems Integrator and Gold Certified Partner, using technologies such as Silverlight 2.0, SharePoint, and Microsoft Dynamics CRM 4.0. Prior to joining Neudesic, Sandeep built applications for the credit card processing industry, using Microsoft BizTalk Server 2004/2006, Windows Workflow Foundation, and Microsoft SQL Server 2005.
Email AuthorEmail Author
Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date