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