CrmService Update method updates wrong type of entity RRS feed

  • Question

  • Dear Friends,

    We are facing a strange behaviour in our app.


    We use CrmService to update one entity, which works ok. However, when we use the same service to update a different entity, the first entity is also updated. We don't know why is that happening. Here is the code segment we are having trouble with:


    Code Snippet

    // Open CrmService
    CrmAuthenticationToken token = new CrmAuthenticationToken();
    token.OrganizationName = ConfigurationManager.AppSettings.Get("Organizacion");
    CrmService proxy = new CrmService();
    proxy.Credentials = System.Net.CredentialCache.DefaultCredentials;
    proxy.CrmAuthenticationTokenValue = token;
    //Retrieve Opportunity
    Guid oportunidad = new Guid("3963176C-0E2C-DD11-8A81-0019D13DDA0E");
    opportunity op = (opportunity)proxy.Retrieve(EntityName.opportunity.ToString(), oportunidad, new AllColumns());
    //from opportunity, find the Guid of the related entity (customized entity called new_unidad), which is stored in the field called new_viviendaid
    Guid Gunidad = op.new_viviendaid.Value;
    string UnidName = op.new_viviendaid.name;
    // update the new_picestado field from the related entity (new_picestado is a picklist)
    new_unidad unidad = new new_unidad();
    unidad.new_picestado = CrmTypes.CreatePicklist(1);
    unidad.new_unidadid = CrmTypes.CreateKey(op.new_viviendaid.Value);

    // at this time, the variable new_picestado in the new_unidad entity is correctly set to 1.
    // update now another picklist from the original opportunity, called new_picdesestimiento
    opportunity opp = new opportunity();
    opp.opportunityid = CrmTypes.CreateKey(oportunidad);
    opp.new_picdesestimiento = CrmTypes.CreatePicklist(2);
    // this last proxy.Update call, changes the unidad picklist value. the variable new_picestado in the new_unidad entity reverts to its previous value (which was 3).




    When the proxy.Update(opp) statement is executed, the variable unidad.new_picestado reverts to its previous value.


    Any suggestions on how to work this out?


    thanks in advance for the help


    Alejandro Dezerega

    Wednesday, December 17, 2008 1:06 PM


  • Do you use "oportunidad" variable two times?

    Guid oportunidad = new Guid("3963176C-0E2C-DD11-8A81-0019D13DDA0E");

    in :

    opportunity op = (opportunity)proxy.Retrieve(EntityName.opportunity.ToString(), oportunidad, new AllColumns());

    and in:

    opp.opportunityid = CrmTypes.CreateKey(oportunidad); <-  why????

    is it?
    Friday, August 21, 2009 11:36 AM