0

I am doing a tool to synchronize some to data between CRM and another application. Now I have to remove the value from a EntityReference. I am trying in this way:

contact.ParentCustomerId = null;

But it does not work. That does not give me any error bur when I go to CRM via browser the field is till valorized. I have also tried in this way:

contact.ParentCustomerId = new EntityReference(Crm.Context.Account.EntityLogicalName, Guid.Empty);

but this give me a runtime error.

How can I solve? Thank you

UPDATE :

 Crm.Context.Contact contatto = ContattiTOA.Transform(c, account); //Inside the transform you can see that line of code I posted before..

 var entityToUpdate = this._context
                                .ContactSet
                                .Where(cont => cont.new_SIP_id == contatto.new_SIP_id || cont.Id == contatto.Id)
                                .First();

        if (entityToUpdate.new_SynchronizewithSIP.HasValue && entityToUpdate.new_SynchronizewithSIP.Value == true)
        {
            contatto.Id = entityToUpdate.Id;
            contatto.OwnerId = entityToUpdate.OwnerId;
            contatto.EntityState = EntityState.Changed;

            request = new UpdateRequest { Target = contatto };
        }

        requests.Requests.Add(request);

        ExecuteMultipleResponse responses = (ExecuteMultipleResponse)this._context.Execute(requests);

        foreach (var responseItem in responses.Responses)
        {
            if (responseItem.Fault != null)
            {
                ... // I never fall in here
            }
        }
Simone
  • 2,304
  • 6
  • 30
  • 79
  • 2
    contact.ParentCustomerId = null; is correct, do you save the record after? – Guido Preite Mar 13 '15 at 14:31
  • yes... All other fields are correctly changed... but not that one... – Simone Mar 13 '15 at 14:32
  • I concur that the line of code is correct, so the bug is likely somewhere else – Alex Mar 13 '15 at 14:47
  • I have done some update so you can see all the code... I did a debug everything seems correct... – Simone Mar 13 '15 at 15:00
  • In the code you posted I don't see the line `contact.ParentCustomerId`. – Nicknow Mar 14 '15 at 01:22
  • It is inside the first line of code... I wrote a comment as you can see.. The `Transform` method is a reallt stupid method... It is just a mapping from my domain object to the CRM object.. In this mapping there is that line of code – Simone Mar 14 '15 at 16:39
  • Have you tried isolating the code to just the contact.ParentCustomerId = null? You may want to try running just that to see if that is for sure your your issue. – BlueSam Mar 14 '15 at 20:42
  • Yes, I have just tried... but no difference – Simone Mar 16 '15 at 09:59

0 Answers0