Dynamics CRM Web Service Execute returns "Server was unable to process request."

0

I'm going crazy here with DCRM web services,

I'm trying to create a Connection between two leads dynamically. I'm getting the following error:

"0x80040216
  An unexpected error occurred.
  Platform
  An unexpected error occurred.

Type:Microsoft.Crm.CrmException ErrorCode:0x80040216
Object reference not set to an instance of an object."

Here is my code:

Guid connectionRoleID = new Guid("64f33a74-0342-e211-b55e-00155d00041e");
connectionroleobjecttypecode connroleobjecttypecode = new connectionroleobjecttypecode() { connectionroleid = new Lookup(){Value = connectionRoleID}, associatedobjecttypecode = EntityName.lead.ToString()};

connection conn = new connection();
List<Property> list = new List<Property>();

Lookup lookup = new Lookup();
lookup.Value = customers[i].ID.Value.Value;
lookup.name = EntityName.lead.ToString();

Lookup lookup2 = new Lookup();
lookup2.Value = customers[j].ID.Value.Value;
lookup2.name = EntityName.lead.ToString();

conn.record1roleid = new Lookup() { name = "duplicate", Value = new Guid("64f33a74-0342-e211-b55e-00155d00041e") };
conn.record2roleid = new Lookup() { name = "duplicate", Value = new Guid("64f33a74-0342-e211-b55e-00155d00041e") };
list.Add(new LookupProperty(){Name = "record1id", Value = lookup});
list.Add(new LookupProperty(){Name = "record2id", Value = lookup2});
list.Add(new LookupProperty(){Name = "record1roleid", Value = conn.record1roleid});
list.Add(new LookupProperty() { Name = "record2roleid", Value = conn.record2roleid });

I've tried tracing (which did not help), and in the eventviewer I get an error, but there is no helpful information.

I'm dying here! Please help... :-)

web-services
dynamics-crm
dynamics-crm-4
asked on Stack Overflow Dec 9, 2012 by user327823 • edited Mar 21, 2014 by Gabriel.Massana

2 Answers

0

I think its because you are doing:

conn.record1roleid = new Lookup() { name = "duplicate", Value = new Guid("64f33a74-0342-e211-b55e-00155d00041e") };

name should be the name of an entity, e.g. contact, lead, incident. In this case I believe you should be using: connectionrole.

conn.record1roleid = new Lookup() { name = "connectionrole", Value = new Guid("64f33a74-0342-e211-b55e-00155d00041e") };

I would suggest having at Sample: Create a Connection (Early Bound).

answered on Stack Overflow Dec 9, 2012 by James Wood
0

Add type for the entity to lookup

Lookup lookup2 = new Lookup();
lookup2.Value = customers[j].ID.Value.Value;
lookup2.name = EntityName.lead.ToString();
**lookup2.type = "lead";**
answered on Stack Overflow Dec 27, 2012 by Hary

User contributions licensed under CC BY-SA 3.0