CRM 4 – When do you use a Moniker instead of a DynamicEntity in a plugin

I read an interesting CRM post today about how to get the new owner of a record in a plugin in CRM 4 and was interesting because the plugin uses a moniker instead of a dynamic entity

The blog post can be summarised by this qutoe


I have developed my plugin which is registered for Create and Update messages on the Account entity. The purpose of the plugin is to update internal ERP system.

Everything is working fine. But…

Problem 1: Update is triggered automatically when the user changes the owner of an account or in other words, when an account is reassigned. No clicking on ‘Save’ or ‘Save and close’ is necessary neither. Just changing the owner triggers the Update when page is being refreshed.

Problem 2: Owner change is still not reflected, so queries like <myaccount>.user_accounts as well as <myaccount>.ownerid always return the old owner.


After asking some colleagues and some research, I found out that I could register my plugin or another plugin (I chose the latter approach) to the Assign message.


The information in the blog post brought up a number of interesting questions.  The fact that assigning entities doesn’t need you to save the record.

It’s also interesting you can trigger a plugin on an assign account, this is something useful to lock away for the future.

Another odd thing I found out recently is in CRM 4 certain context parameters are Monikers

Moniker entity = null; // what you get as Target in an Assign message is a moniker

            if (context.InputParameters.Properties.Contains("Target") &&
                       context.InputParameters.Properties["Target"] is Moniker )

I didn’t know what a moniker was until recently, it isn’t used for update or create plugins but is used on Delete and assign and other plugins.

You can see what values a Moniker has here

This blog explains input and output parameters below is a line which I think explains what values a moniker has.

Target was of type -Microsoft.Crm.Sdk.Moniker having Id of the record to be deleted and name as lead

I then found this forum post which shows you how to test for a target

ou can test whether or not the InputParameters collection “contains” something, and you can also test an object’s type by using an “if” statement that uses the “is” keyword.  A la:

if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is DynamicEntity)
 // Work with the DynamicEntity

if (context.InputParameters.Contains("EntityMoniker") && context.InputParameters["EntityMoniker"] is Moniker)
 // Work with the Moniker

You may be able to spool through the InputParameters, PreEntityImages, and PostEntityImages collections using this code (but I haven’t tested it, so your mileage may vary):

foreach (PropertyBagEntry property in context.InputParameters) {
 if (property.Value is DynamicEntity) {
  // The property is a DynamicEntity
  // property.Name can be tested to evaluate as "Target"
 else if (property.Value is Moniker) {
  // The property is a Moniker
  // property.Name can be tested to evaluate as "EntityMoniker"

I seemed to have gone off topic a bit here, the rest of the original blog post I was talking about basically returns the owner (SystemUser) class.


CRM 2011 – Upgrading CRM 3 to CRM 2011

Recently someone asked this blog if I had an information on upgrading CRM 3 to CRM 2011.

This is one of those scenarios where a small piece of knowledge gained from passing a CRM certification came into my mind.  For one of the CRM exams (I’m guessing the CRM 4 installation exam) you have to learn that with CRM you cannot skill versions when upgrading and you have to upgrade one step at a time.

So if you are upgrading CRM 3 to CRM 2011 you would first have to upgrade to CRM 4 and then upgrade to CRM 2011.

I found a couple of useful forum with some good advice on resources for upgrading to CRM 2011 from CRM 3, it also made me think how useful the forums are.

This forum post was particularly useful, although it does concentrate on upgrading CRM 3 to CRM 2011 online it still covers a lot of the steps you will go through.

The first thing you should read if you are upgrading to CRM 2011 is the implementation guide which you can find here

I think the most important thing you need to consider is how many customermizations you have because these are going to add to the complexity of the upgrade and will need a lot testing.

The forum suggests using Scribe (which although I haven’t used I have heard very good things about) which will save you a lot of time.

I also found some great articles on upgrading from CRM 3 to CRM 4, which is what you are going to have to do first before you then upgrade from CRM 4 to CRM 2011, here is a video about importing an organisation into CRM 2011 from CRM 4 but first you need to read the article below

One of the problems discussed in the forum seems to discuss is getting the notes out from CRM 3 .

The quote below is taken from the forum

Here is a sql query that you can drop into SLQ Management Studio that will pull the notes related to Cases as well as the related Case #.  You’ll want to save the data off to a csv file for importing and ensure your Header Row matches exactly the Display label of each field so that the import can easily map the fields.

You can add any additional fields as needed.  I tried to grab most of the ones that I thought were relevant.

select n.subject as ‘subject’, n.notetext as ‘notetext’, n.filename as ‘filename’,
n.annotationid as ‘annotationid’, n.isdocumentname as ‘isdocumentname’,
n.owneridname as ‘owneridname’, i.ticketnumber as ‘i.ticketnumber’ from FilteredAnnotation as n
join FilteredIncident as i on (n.objectid  =  i.incidentid and (i.ticketnumber is not null)) order by n.subject asc, n.annotationid asc

I didn’t test this all the way through so let me know if you run into any issues. You may need to remove annotationid from the query as CRM will think you want to update Notes rather than import new Notes


The forum also discussed this method

For each entity that you want to migrate data from, open up a view. Then click Advanced Find. The current view will be loaded into Advanced Find and you can select which records to migrate (by applying criteria) and which columns to export (by using Edit Columns feature).

Note that there are some big limitations with this approach:

  • You’l have to import the records in sequence. For example, you need to import opportunities after importing accounts and contacts. It’s worth spending a few minutes thinking about the sequence to ensure all ‘parent’ records are imported before any dependent ‘child’ records.
  • You won’t be able to migrate any attached files — these cannot be exported to Excel.

The new CRM Online import wizard is another big improvement over similar features in CRM 3.0 and 4.0, but there are few blog resources available to help if you run into any issues.