CRM Blog

Customer Address - Error When Creating New Via Web Services

by Danny Varghese 03.10.08
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();

Filed under:

Comments

# sander said on December 22, 2008 07:24 AM:

Hello. Just saying thanks for this article for it saved me some of my hair when dealing with the 'unknown error' I was getting. Great finding :)

# Mark Johnston said on January 5, 2009 11:13 AM:

Bravo! This one had me stumped. Your suggestion is right on the money.

The odd thing about it is that the cutsomeraddress.objecttypecode is flagged as read-only in the SDK documentation.

I never would have thought to try this without your help. Thanks again!

# Plugin error: "Server was unable to process request" | keyongtech said on March 2, 2009 05:09 PM:

Pingback from  Plugin error: "Server was unable to process request" | keyongtech

# Ryno said on September 7, 2009 04:46 AM:

Great find. You saved me hours of un-pleasant trial and error coding.

Leave a Comment

(required) 
(required) 
(optional)
(required) 
Security Check
Please answer the simple math problem below.

(required)