CrmService.Update method does not work for certain attribute

1

This is my problem: all I want to do is update a "contact" entity in Crm 4 using the webservice.

This is my code:

CrmService eatupCrmService = CrmInteraction.InitializeCrmService();
contact updatedDelegate = new contact();
CeatupCrmService.Key contactPrimaryKey = new CeatupCrmService.Key();
contactPrimaryKey.Value = delegateId;
updatedDelegate.contactid = contactPrimaryKey;
updatedDelegate.address2_postalcode = delegateDetails.ContactDetailsPhysicalAddressCode;
eatupCrmService.Update(updatedDelegate);

I use the InitializeCrmService() to also retrieve and it works. When updating the address2_postalcode attribute, I get the following error:

"Server was unable to process request."

with the exception Detail\InnerText :

"0x80040216 An unexpected error occurred. Platform".

If I change the code to update another attribute, say I try to update the mobilephone attribute instead of address2_postalcode it works without any exceptions thrown.

As soon as I try to update address2_postalcode then I get that error. The address2_postalcode data type in Crm is nvarchar, and the value it is being assigned (delegateDetails.ContactDetailsPhysicalAddressCode) is of c#'s string type.

Anyone have any idea why this could be happening?

c#
dynamics-crm-4
asked on Stack Overflow Oct 16, 2011 by Matei • edited Oct 16, 2013 by Gowri

3 Answers

2

This same error and situation happened to me because I did an SSIS dts to load contacts in CRM from a flat file, in unsopported way, and I forgot to fill the CustomerAddressBase table. After filling this table "correctly" (two rows for each contact) the attributes of the View CustomerAddress(address1_addressid and address2_addressid) became not null. If you don't know how to fill this table (CustomerAddressBase) just create one new contact directly with address fields filled in CRM and then go to SQL Server management studio and by query you can see and know how the fields are filled.

Hope it helps somebody,

Alex

answered on Stack Overflow Nov 5, 2012 by Alex
1

After many attempts at trying to understand why this error was occurring, I finally succeeded.

When I started working on this project, the client instructed me to test using only a specific contact, because we were working directly on the production environment. (the client does not have a development environment yet)

After doing some database queries to compare this contact to others (updates were failing only for the test contact) I noticed that my contact's address2_addressid attribute was NULL.

I then went to CRM under Customization\Customize Entities and opened up the contact entity. Under attributes, I ordered by type and saw that the contact has 3 primarykey attributes: contactid, address1_addressid and address2_addressid.

The test contact's address1_addressid and address2_addressid fields were NULL and this caused the CRM web service to throw the 0x80040216 An unexpected error occurred. Platform error upon me trying to update any of the address fields.

I don't know why this contact had those IDs set to NULL, I asked and the person that created the contact had no explanation of how this could have happened. I guess this will remain a mystery, but at least I now have an answer to the error I was getting and I can cater for this in my code.

answered on Stack Overflow Oct 23, 2011 by Matei • edited Oct 23, 2011 by Shadow The Vaccinated Wizard
0

I don´t know ho it can work... I think you have to do CrmService.Create(contact) and then with the returned Guid you can perform updates...

Update is not going to work since the record with the Id you are setting on your contact entity doesn´t exist in the db...

contact updatedDelegate = new contact(); 

CeatupCrmService.Key contactPrimaryKey = new CeatupCrmService.Key();

You could do something like:

crmService eatupCrmService = CrmInteraction.InitializeCrmService();
        contact updatedDelegate = new contact();
        updatedDelegate.address2_postalcode = delegateDetails.ContactDetailsPhysicalAddressCode;
        Guid cId = eatupCrmService.Create(updatedDelegate);
        updatedDelegate.contactid = new Key(cId);
        //set more fields if you want
        eatupCrmService.Update(updatedDelegate);//update record

Wish I have helped you.

answered on Stack Overflow Oct 17, 2011 by Jorge Utrilla

User contributions licensed under CC BY-SA 3.0