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


CRM 4 – Remote debugging not working – things to check

I recently had a problem trying to set up remote debugging and it was very frustrating.  I thought I would document my findings here in hope it might help someone who is trying to setup remote debugging (or might in the future).

I won’t go through setting up remote debugging in this blog post but if you want more information on that I have written a couple of blog posts before which will help you

an example of setting up remote debugging

general help and videos on setting up remote debugging

I had downloaded the Remote debugger and set it up.

When I tried to connect to the remote debugger from my machine, it wouldn’t let me access it.  I found it would only let me access the remote debugger if I went to options and chose no authentication.

looking back this was really trying to get round the underlying problem rather than fix it.

I also found I had problem access a new web site I added to the server.

When I tried remote debugging like this, I wasn’t get any response to my machine and everything seemed to freeze until it basically timed out.

I did a couple of things to sort this out.

The most import action was to add my user to the administrator group on the machine.  After I did this I could then connect to the remote debugger as my user

I also changed a setting on my firewall settings to inform me when applications were being blocked.  I couldn’t find any settings which might be blocking.  Although I’m not sure if it was the change above which fixed this issue because then Visual Studio told me remote debugging was being blocked and I could choose to allow it.

Make sure you runt he remote debugger as an Administrator.


I also learnt thanks sosoto reply to one of my previous blog posts you can debug plugins registered in the database all you have to do is copy the pdb file to CRM folder –  \Server\bin\assembly folder

here is his full comment

You cannot remote debug if you don’t deploy to disk

i disagree. It is possible to debug a database deployed plug-in. The compiled plug-in assembly’s .pdb file must be copied to the server’s \Server\bin\assembly folder and IIS must then be restarted. After debugging has been completed, you must remove the .pdb file and reset IIS to prevent the w3wp.exe process from consuming additional memory.

CRM 2011 Solution – Shrpr Web Resource Editor

The file editor when editing Web Resources is as basic as they come in CRM 2011 (and all the previous versions).  It would be such a nice gesture for Microsoft to create an editor with a few basic features like syntax checking and formatting.

Microsoft have yet to do anything in this area so one someone got bored of waiting and has started the process by creating the Shrpr Web Resource Editor.   You can read more about the editor in this blog post and you can download the solution (a CRM solution which you can import) here  Downloads 

It has features like

Syntax highlighting

Line numbering

matching braces

simple code completion


When I imported the solution I couldn’t figure out where the editor was or if it did anything, this was because I went into a form and tried editing some Javascript.  Unfortunately there isn’t any documentation yet so you have to figure it out yourself.  After reading the title again, I went to Web Resource and then clicked on some javascript, you then see there isa new button on the top right to open the web resource with the editor.   Below is a screenshot


I think this is a really good start because syntax highlighting is very useful and the matching braces is fantastic.  Hopefully if people start using it and giving some feed back he will continue to work on the product.

So thanks Roman Gebesmair and keep up the good work