How CRM 2011 Caching Works

Another great article on Develop 1 Blog talks about how caching works in Dynamics CRM 2011. The original article can be found here. The article explains a problem the person was facing with his/her ribbon customization, after publishing wasn’t showing up.

The article goes on to say how there is a JavaScript method that takes in two parameters indicating the metadata version and ribbon version.  Each time a change is made, one or more of those parameters should increment. The ribbon version was not being incremented. According to this blogger: “The CRM 2011 cache is stored in the standard ASP.NET HTTP Cache – and it was this cache that holds the Ribbon Version. The publish is meant to invalidate this cache so that the new version can be used. Without this cache, every single request would have to hit the database to load customization XML…Upon investigating how the CRM2011 cache is managed – there is a Notifications table in the MSCRM_CONFIG database that includes entries that instruct CRM to clear cache items. The Async Server picks these up and notifies the HTTP Worker processes to drop each cache by Key.”

The issue was in previous testing, this blogger changed the time on the server to one month ahead.  He/she believes the async service wakes up and uses the current date/time to query the database for what items to clear from cache.  If records are being inserted into the database using the server’s date & time (which was set to one month ahead), the query was not picking up these notifications in the table, and thus not clearing the cache.

I found this article extremely interesting!!  Props to the author!

Import Solution Progress Window Un-responsive

A colleague of mine, Charles Fabiano, stumbled upon this blog: Develop 1 Limited Blog.  I started browsing through some posts and came across this very interesting article: Un-responsive Import Solution Dialog.

When importing a solution into Dynamics CRM, and you’ve ever seen the progress window “freeze up,” this solution allows you to see if the import is still going on.  Please note that this is for an on-premise installation only.

Sample CRM 2011 Retrieve and Retrieve Multiple

Thank you to all who have been reading my blog articles and have commented and sent personal messages.  It means a lot to me to know some of my content might be helping.  A common request I get is to post sample code on some basic operations using web services.  I’ll try to do that in the upcoming articles.  For those of you that are seasoned CRM developers, this might be redundant and I apologize!

The method GetCRMService() is a private helper method used to retrieve an instance of the CRM web service. This particular method authenticates both on-premise IFD and non-IFD deployments. Please note, authenticating to a CRM online environment is a different solution. Also note that this particular method does not provide early binding support. I will discuss all of these possible options in a later article.

private IOrganizationService GetCRMService()
{
     OrganizationServiceProxy serviceProxy;
     const string uri = "uri";
     const string userName = "username";
     const string password = "password";
     const string domain = "domain";

     IServiceConfiguration<IOrganizationService> config = ServiceConfigurationFactory.CreateConfiguration<IOrganizationService>(new Uri(uri));

     if (config.AuthenticationType == AuthenticationProviderType.Federation)
     {
          // ADFS (IFD) Authentication
          ClientCredentials clientCred = new ClientCredentials();
          clientCred.UserName.UserName = userName;
          clientCred.UserName.Password = password;
          serviceProxy = new OrganizationServiceProxy(config, clientCred);
     }
     else
     {
          // On-Premise, non-IFD authentication
          ClientCredentials credentials = new ClientCredentials();
          credentials.Windows.ClientCredential = new NetworkCredential(userName, password, domain);
          serviceProxy = new OrganizationServiceProxy(new Uri(uri), null, credentials, null);
     }

     return serviceProxy;
}

An example of retrieve a single record, given the record id is below:

public Entity RetrieveRecord(string entityName, Guid recordId, ColumnSet columns)
{
     return GetCRMService().Retrieve(entityName, recordId, columns);
}

An example of retrieving multiple records is below:

public IEnumerable RetrieveRecords(string entityName, ColumnSet columns)
{
     QueryExpression query = new QueryExpression
     {
          EntityName = entityName,
          ColumnSet = columns,
          Criteria = new FilterExpression
          {
               Conditions =
               {
                    new ConditionExpression
                    {
                         AttributeName = "attributeName",
                         Operator = ConditionOperator.Equal,
                         Values = {"attributeValue"}
                    }
               }
          };
       }

       return GetCRMService().RetrieveMultiple(query).Entities;
}

New CRM 2011 SDK Release

I know this is a bit late, but for those who don’t know yet, the new CRM 2011 SDK has been released as of October 11, 2012 (10/11/12 – not sure if that was on purpose), and can be downloaded here. According to the sdk download site, the changes made are:

“All assemblies have been updated. The FilterExpression.IsQuickFindFilter property introduced in UR10 was removed. The functionality is still present in FetchXML but will not be available in QueryExpression until a future release. This change is not reflected in the CHM or documentation on MSDN.”

CRM 2011 Export to Excel Limit

CRM 2011 allows users to export records from a view to Microsoft Office Excel with a click of a button.  CRM can export all records in that view, but has a configured limit of 10,000 records.  This is just my guess, but from developing custom .NET web application in the past, I believe the limit is in place for performance gains.

When a .NET web application has a bunch of data it needs to place in excel, the request is made, and the information is retrieved from the database, inserted into an excel spreadsheet and temporarily placed on the web application server.  Then when a user click’s save or open on the dialog, the spreadsheet is then streamed to the user.  The larger the data, the larger the file, thus creating a larger file stream causing a hit on performance.

That said, in may organizations, the 10,000 record is not realistic.  In that case to increase the limit, use the statement below:

-- sets record limit to 100,000 --
UPDATE OrganizationBase
SET MaxRecordsForExportToExcel = 100000

To verify the query worked, here’s the select statement:

SELECT MaxRecordsForExportToExcel
FROM OrganizationBase