locked
Convert this CRM 4.0 code to CRM 2011 RRS feed

  • Question

  • Hi All,

    Please help me to convert this 4.0 code to 2011.

    public void Execute(IPluginExecutionContext context)
    {
    if (context.MessageName == MessageName.Create &&
    context.InputParameters.Contains("Target") &&
    context.InputParameters["Target"] is DynamicEntity)
    {
    DynamicEntity entity = (DynamicEntity)context.InputParameters["Target"];

    //Check that target entity is contact
    if (entity.Name != EntityName.contact.ToString())
    return;

    //Check that this contact is created in the way of
    //convertion from lead
    if (!entity.Properties.Contains("originatingleadid"))
    return;

    //Source Lead Identifier
    Guid leadid = ((Lookup)entity["originatingleadid"]).Value;

    //Target Contact Identifier
    Guid contactid = (Guid)context.OutputParameters["Id"];

    ICrmService crmservice = context.CreateCrmService(true);

    //Just build the query which will be used to retrieve
    //all child annotations (notes and attachements)
    QueryByAttribute query = new QueryByAttribute();
    query.ColumnSet = new AllColumns();
    query.EntityName = EntityName.annotation.ToString();

    query.Attributes = new string[] { "objectid" };
    query.Values = new object[] { leadid };

    RetrieveMultipleRequest request = new RetrieveMultipleRequest();
    request.Query = query;
    request.ReturnDynamicEntities = false;

    RetrieveMultipleResponse response = (RetrieveMultipleResponse)crmservice.Execute(request);

    foreach (annotation note in response.BusinessEntityCollection.BusinessEntities)
    {
    //Just remove Key field of annotation
    note.annotationid = null;

    //Replace referencing object lookup with newly created contact lookup
    note.objectid = new Lookup(EntityName.contact.ToString(), contactid);
    note.objecttypecode = new EntityNameReference(EntityName.contact.ToString());

    //And Create the annotation record
    crmservice.Create(note);
    }
    }
    }

    And also please give me the valuable input for how to expertise in developing plugins. I am going through the SDK and how efffective we can use SDK for developing plugins. 

    I would be most happy if anybody share me the plugin samples from small to large plugins.Thanks in advance. please understand my anxiety.


    Thanks & Regards, Sudhakar

    Tuesday, March 27, 2012 1:01 PM

All replies