Monday 17 June 2013

CRM 2011 OData XMLHttpRequest Maximum Length

I had a requirement where I wanted to know if a user had a particular system role.  I created a function which returned all User Roles with a particular name (System Administrator for example) and compared this to what gets returned from Xrm.Page.context.getUserRoles().

This worked in the Development and Testing environments so it was pushed to Production.  When in Production the function failed to recognise the correct Roles which made no sense.

After wasting several hours of my life I discovered that the issue was related to the relationship between Business Units and Roles.

The Production environment had 60+ business entities where Development and Testing had much less.  The 60+ business units meant that CRM created 60+ versions of the Security Roles so searching for "System Administrator" returned over 60 records.

The page length for XMLHttpRequest OData requests through the CRM Web Service is fixed at 50.

Rather than repeat the solution here I suggest you look at Lakshman Reddy's blog which is what lead me to my fix.

http://lakshmanindian.wordpress.com/2012/12/07/retrieving-more-than-50-records-using-odata-in-crm-2011/

The only issue I had was the process of returning all those Roles slowed down my CRM page.  So I instead reversed my query for example.

Original
Return all Roles with 'System Administrator' name then compare with User Roles.

Updated
Return all Roles where Guid is in User Roles

Dynamics CRM 2011 Authentication Types

Connecting to CRM 2011 (in particular CRM Online) can be tricky due to the different authentication methods on offer. If you are allowing users to connect to CRM using different authentication types then you need to be aware of the different requirements


  • Windows Live Id (WLID)
    • Device Registration
    • Username
    • Password
  • Office 365 - (Online Commerce Platform) (OCP)
    • Username
    • Password
    • Security Token using Username/Password
  • Active Directory
    • Domain
    • Username
    • Password
  • Federated
    • Username
    • Password

Dynamics CRM 2011 - "An error occurred when verifying security for the message"

If you attempt to connect to the Dynamics CRM 2011 Web Services using SOAP you may come across this message "An error occurred when verifying security for the message".

In most cases this will be an issue of the server and client times not being close enough so they web server rejects the request.

However I was receiving this message for a completely different reason.

I was using the "CRMOnlineSOAPRequests" example written in C# as a base reference point however I wanted to write my code in PHP so I googled and found a couple of good examples.

Both the C# code and my PHP code returned the required tokens when authenticating however the second token was always 6764 characters in length while the PHP second token was 6796 in length.

I then discovered that I was attempting to connect to the wrong region for my authentication!

If you are receiving this error then ensure that you have selected the correct URN for your region.

  • crmna:dynamics.com - North America
  • crmemea:dynamics.com - Europe, the Middle East and Africa
  • crmapac:dynamics.com - Asia Pacific