A CRM 2013 Azure Portal for Xmas

Kev Xmas Portal

Introduction

Continuing my experience of playing with and learning about Dynamics CRM 2013, my next challenge was to build my first web portal on Azure that interacted with data held in a CRM online trial instance.  This article provides a step-by-step walk-through of that experience and I hope it might be of use for anyone else getting to grips with the basics of portal creation.

The resulting portal site can be visited at: –

http://kevxmas.azurewebsites.net

Pre-Requisites

The tool set/systems that I used for this build were: –

  • My MSDN subscriber account on Azure.  You can sign up for a free trial at https://www.windowsazure.com
  • A free 30-day online trial of Dynamics CRM 2013.  You can sign up for this at http://crm.dynamics.com
  • Visual Studio 2012 as my integrated development environment (IDE).  Download from your MSDN account if you are a subscriber or chose another IDE of your own preference.
  • A free Xmas-themed CSS from http://www.smopic.com
  • The Dynamics CRM 2013 Software Developer Kit (SDK) for samples and ideas.
  • The CrmSvcUtil.exe tool which ships as part of the SDK.  When you unzip the SDK you will find it in directory SDK\Bin
  • I wanted a nice Light Box effect for my Xmas Advent calendar and so used the lightweight jQuery Fancybox.  Screenshot below.

KevXmas2

Xmas Advent Calendar

I had already created a CRM 2013 solution containing the personal address book data of my friends in a previous exercise.  You can read about that in my “Hello World” blog post.  So using that as the foundation my portal idea was to set up a Xmas countdown advent calendar where each door revealed a photo that invited my friends to take part in a caption competition.  The same site was also to allow the visitors to look up the data held about them in CRM and amend it if necessary.

Finally I was going to run a classic marketing campaign out of CRM to inform all my contacts that the site existed when it was finished.

The Portal Build

The build proceeded as follows: –

  • Registered for a 30-day trial CRM and then loaded my address book solution in to this and my friend’s data.
  • Extended this solution to create a simple custom “caption” entity that I would use to store the entries for the caption competition.  This simply needed to store two text fields (name of submitter and the caption itself) and the day of December for which the caption was submitted.  A screenshot of the caption entry list page in CRM is below.

KevXmas3

  • Logged in to Azure and requested a new website to be created.  The connection details for this site are shown on the Dashboard page.
  • Opened the command prompt and navigated to the folder in which I had extracted the CRM 2013 software development kit – under the Bin sub-folder the CrmSvcUtil.exe tool can be found.  This tool is used to interrogate an instance of Dynamics CRM and build a .Net class that models all the entities.  This class can then be included in projects that work with the CRM (such as my portal) to provide early binding of class types for working for CRM data.  This means that we can write strongly typed code with full support for IntelliSense and compile-time validation that nothing is awry.  Here’s an MSDN Article about using the tool.
  • The format for using this tool (your data to replace the parts in capitals) is: –

CrmSvcUtil.exe
/url:https://YOURURL.crm4.dynamics.com/XRMServices/2011/Organization.svc
/out:NAMEOFFILETOGENERATE.cs
/username:YOURLOGIN@YOURCRMDOMAIN.onmicrosoft.com
/password:YOURPASSWORD
/namespace:NAMESPACEFORYOURCLASS.Xrm
/serviceContextName:CONTEXTNAME

  • With the .cs class file generated I was now ready to begin work on the portal itself.
  • I chose the ASP.NET Web Forms Application Template from within Visual Studio 2013, chosing to work in c#.
  • I created a simple website of three pages with the CSS applied SmoPic.  The pages were: –
    • The advent calendar itself, 25 photos of my family with some c# code-behind controlling access based on the current server date.  the jQuery Fancybox code was integrated to give up a pop-up showing a larger version of each photo and the form for caption competition entry.
    • A “My Data” page in which visitors could enter a code I was to give them by email and access the data stored about them in CRM.
    • A caption review page with a simple ASP.NET data grid extracting and displaying the captions entered to date.
  • I extended the samples in the CRM 2013 SDK to create a basic CRM connection class and helper class to allow my code-behind to communicate with CRM.  The URL and login details were stored in the site web.config.
  • Captions were submitted by creating instances of the caption type provided in the class generated by CrmSvcUtil.exe.  for example: –

// Use the avdemo_captionentry created in the CRM class by SvcCRmUtil.exe and
// populate its attributes with values from the portal web form.  Use the
// Create method against the CRM proxy to create this record and returns its
// global unique identifier (GUID) assigned by CRM
avdemo_captionentry newCaption = new avdemo_captionentry();
newCaption.avdemo_Day = dayNumber;
newCaption.avdemo_name = txtName.Text;
newCaption.avdemo_caption = txtCaption.Text;
Guid _newCaptionId = crmAddressBookProxy.Create(newCaption);

  • Any data retrieved from CRM used LINQ syntax, for example: –

// Working against the CRM, execute a LINQ query to return the captions entered to date
// and bind these to a ASP.NET Grid View on the web form
gvCaptions.DataSource = crmAddressBook.avdemo_captionentrySet.ToList().OrderByDescending(x => x.avdemo_Day).OrderByDescending(y => y.CreatedOn);

  • This site was ran and tested locally out of VS 2012.
  • Once satisfied I published the site directly from Visual Studio in to Azure following the instructions on this blog.
  • As a last step I executed a marketing campaign from CRM with a template email with a link to the new site to invite friends to connect.  I added an AccessCode field to the contact entity which I populated with random data uploaded from MS Excel for friends to use to access their information.

Conclusion

I know this article has remained very high level and not provided a throughly detailed walk-through but I wanted to highlight the main experience points that: –

  1. The CRM SDK provides some excellent resources and classes for connecting to and working with Dynamics CRM.
  2. Using CrmSvcUtil.exe is optional but if you do use it to provide early binding it simplifies how you write and validate your code.  Without it you need to rely on more generic CRM classes – an approach called late binding.
  3. The experience of publishing directly from Visual Studio 2012 to Azure was painless and very slick.
  4. At the time of writing there were no CRM Templates for Visual Studio 2012, they exist for VS 2010 I believe but had not yet been updated.  Had they existed (or had I been prepared to use VS 2010) I believe Microsoft provides a CRM portal template to make this sort of build even quicker.
  5. Overall the experience was pretty straightforward so that portals to expose CRM data can be quickly provisioned.
Advertisements

Posted on December 19, 2013, in CRM General. Bookmark the permalink. 1 Comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: