CRM 2011 plugin for updating records: I need all attributes, the changed and not changed ones can i merge them and create stronly typed class RRS feed

  • Question

  • Hi,

    my create plugin works totaly fine and i used stronly typed classes to my the entity class.

    After that i wrote plugin which only handles updates in the pre-validation stage. During this stage only PreImage is available. The plugin needs to do some calculations and for that i need always the complete updated record. This not possible because old values and not changed values are in the PreImage and the changed ones in the Target.

    Is there a better way to merge them and create then a stronly typed instance ?

    Currently i am doing a hack(see code below) and do a manual merge of all the Attributes in Target and hang them into the attributes array of PreImage and create then a stronly typed instance/class of it.

    Don't know if this breaks anything later. The other way would be to write a little helper which checks first if the attribute is in Target and if not it takes it from PreImage so i always get the updated vales or the not changed ones, but i can not use strongly typed classes anymore and no intelli sense.

    Any ideas ?

    Kind Regards


    CrmStronglyTypedClasses.prg_abrechnungsposition dienstleistungposition = ((Entity)localContext.PluginExecutionContext.InputParameters["Target"]).ToEntity<CrmStronglyTypedClasses.prg_abrechnungsposition>();

                Entity EntityPreImage = null;
                CrmStronglyTypedClasses.prg_abrechnungsposition preImageDienstleistungposition = null;
                if (localContext.PluginExecutionContext.PreEntityImages.Contains("PreImage") && localContext.PluginExecutionContext.PreEntityImages["PreImage"] is Entity)
                    EntityPreImage = (Entity)localContext.PluginExecutionContext.PreEntityImages["PreImage"];

                    foreach (KeyValuePair<string, object> value in ((Entity)localContext.PluginExecutionContext.InputParameters["Target"]).Attributes)
                        EntityPreImage.Attributes[value.Key] = value.Value;
                    preImageDienstleistungposition = ((Entity)localContext.PluginExecutionContext.PreEntityImages["PreImage"]).ToEntity<CrmStronglyTypedClasses.prg_abrechnungsposition>();

    Friday, November 22, 2013 9:13 AM


  • This pattern is the one I us, and I've not found a better approach. The only difference is that I normally use the generic Entity class, rather than the strongly-typed classes, but I still merge the attributes of the image and the target

    Microsoft CRM MVP - http://mscrmuk.blogspot.com/ http://www.excitation.co.uk

    • Marked as answer by Markus Benz Thursday, November 28, 2013 12:19 PM
    Tuesday, November 26, 2013 2:32 PM