CRM 2011 Lazy Loading of Attributes

Recently, I had been having a CRM issue. I needed to retrieve the CreatedBy attribute for a customer CDH entity, so I could compare it to the current user for some approval business logic.

I attempted the usual in LINQ:

crm_blog_5-30

 

But, no matter what I did, the field was always null (even though the values returned in LINQPad fine). Then, I discovered that for certain attributes that represent associations or links, CRM does not load the values by default.

 

The missing piece is to manually call the LoadProperty on the OrganizationServiceContext, and then the attribute is populated.

crm_blog_5-30_2

This was quite difficult to figure out, so I hope this saves someone else some time troubleshooting!

 

Here is the link to the LoadProperty Function: http://msdn.microsoft.com/en-us/library/microsoft.xrm.sdk.client.organizationservicecontext.loadproperty.aspx

 

Written By Shawn Strayer, Web Developer at Rockton Software www.rocktonsoftware.com.

Show Buttons
Hide Buttons