CRM 4 – How to create a LookupProperty in a plugin

When Microsoft wrote the api for CRM 4 someone in their infinite wisdom thought it would be a great idea to have lots of CRM variables and lots of property variables.

This meant that developers had to spend hours casting variables to and from the CRM variables.

After a while you do get the hang of it but there are also some unusual variables

Like Key, Lookup, Customer etc.

The LookupProperty variable is quite a tricky one to get your head around

the offical SDK documentation doesn’t really help, have a read here

what did help was a plugin with an example, which I found in this example which shows plugins working for the outlook client.

This is the code to create a lookup property for my custom entity

Lookup salesPersonLookup = new Lookup(“new_salesperson”, crmkey.Value);

LookupProperty lookupProperty = new LookupProperty(“new_salespersonid”, salesPersonLookup);


first you need to create a lookup, this has the syntax of

new Lookup(“entity name”, guid of entity to lookup)

then you need to add the lookup into a LookupProperty

new LookupProperty(“field name”, Lookup)

You then add this property to your property bag and you will be able to update that property

3 thoughts on “CRM 4 – How to create a LookupProperty in a plugin

  1. jkmscrm November 17, 2011 / 2:13 pm

    It’s good that they changed almost all the types in CRM 2011 to .net types making developer life easier :)..



    • Hosk November 17, 2011 / 3:17 pm

      in my opinion that’s one of the best features of CRM 2011. It will save me hours of casting variables.

      I’m not sure whey they made their own variables, I believe it was because CRM values can have nulls or something like that.


  2. CRM for real estate November 25, 2011 / 8:33 am

    I read this post and I think That we can customize throw The options for managing Microsoft Dynamics CRM forms dynamically has increased tremendously in CRM 2011 – we can now, more than ever, tailor the look of a form to the specific type of record displayed.
    Here are 2 functions I use to manage the form at runtime to show or hide sections or tabs based on data in the form.


Leave a Reply

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

You are commenting using your 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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.