Issue
I’ve run into an issue where I get an error message “Server Was Unable To Process Request,” when trying to create a new customer address record via .NET CRM web services.
Required Fields And Web Services
When using .NET and CRM web services to create a record, each entity may have certain required fields that need to be set in order to be created, thus maintaining data integrity. For example, Say you were to make the “Name” field required on an Account record in CRM via customizations. Then on an event of another entity, you wish to use .NET CRM web services to create a new account, you would have to set the “Name” field to some value.
The Trap
The trap here is when you’re developing your code; there are no indicators on which fields are required. In fact, your program will compile fine. However, when you go to run your tests, you’ll see an error in the windows event log “Server Was Unable To Process Request…” This is a very generic CRM error and can be difficult to trace. If you get this error and you were trying to create a new Customer Address entity, it can be a little bit more complicated.
The Solution
When creating a Customer Address entity via web services, unlike many entities, there’s an extra parameter that needs to get set. This parameter (in red below), indicates whether the customer address is associated to an Account (objecttypecode = 1), or Contact (objecttypecode = 2).
customeraddress custAddress = new customeraddress(); custAddress.parentid = new Lookup();custAddress.parentid.type = EntityName.account.ToString();custAddress.parentid.Value = accountId; //sets the objecttypecode value to that of the account system entitycustAddress.objecttypecode = new EntityNameReference();
custAddress.objecttypecode.Value = EntityName.account.ToString();