views:

396

answers:

1

I am trying to make a simple plugin for MS Dynamics CRM 4.0 where send data of a salesorder in a SOAP message on the update of the order. The strange thing is that I get this error every other time i try to save /(execute the plugin). So when I update (any field) of a salesorder and then save I get the error:

The given key was not present in the dictionary.

When I save again right away after that(without even changing anything in between the two saves) it executes correctly and gives me all data I want. It is really every time the same thing: first save: error, second save: execute correctly.

Any ideas what this could be?

This is the first part of my code; where it actually gets the dataset of the salesorder in this case:

   public class CompleteOrderPlugin : IPlugin


    {      


        public void Execute(IPluginExecutionContext context)
        {




                DynamicEntity entity = null;
                if (context.InputParameters.Properties.Contains(ParameterName.Target) &&
                        context.InputParameters.Properties[ParameterName.Target] is DynamicEntity)
                {

                    entity = (DynamicEntity)context.InputParameters[ParameterName.Target];
                    if (entity.Name != EntityName.salesorder.ToString()) { return; }

                }
                else
                {

                    return;
                }

The rest is where I use values from attributes to fill my own variables.

+1  A: 

I fixed this by first making a Post Image of the salesorder in the plugin regsitration tool and then using the values in the Post Image instead of the ones comming directly from the salesorder. This I did because on a update you get only the values that actually changed.

AaronTjong