如果属性parentcustomerid不为NULL,则MS CRM 2013属性parentcustomeridtype不能为NULL

问题描述:

亲爱的聪明的开发人员,

Dear smart developers out there,

当我想通过Web服务在Microsoft Dynamics CRM 2013中创建属于组织的联系人时遇到问题

I encounter a problem when I want to create a contact belonging to an organization in Microsoft Dynamics CRM 2013 via web services

client = new OrganizationServiceClient("CustomBinding_IOrganizationService"); 
var newContactProperties = new Dictionary<string, object> { 
                { "lastname", "TestContact"}, 
                { "firstname", "A"},
                { "fullname", "A TestContact"}

        };

/* organizationType is a CRM.CRMWebServices.OptionSetValue
 * with ExtensionData null, PropertyChanged null and a valid Value
 *
 * orgReference is a CRM.CRMWebServices.EntityReference
 * with a valid Id
 */

newContactProperties.Add("parentcustomeridtype", organizationType);
newContactProperties.Add("parentcustomerid", orgReference);

var entity = new Entity();
entity.LogicalName = "contact";
entity.Attributes = new AttributeCollection();
entity.Attributes.AddRange(newContactProperties);

client.Create(entity);

这给我错误'如果属性parentcustomerid不为NULL,则属性parentcustomeridtype不能为NULL '

我很困惑为什么会发生这种情况以及如何解决这个问题.如果可以的话,请帮助我.

I am puzzled why this happens and how I can solve this problem. Please help me if you can.

谢谢你,AllWorkNoPlay

Thank you, AllWorkNoPlay

您无需单独设置"parentcustomeridtype"属性.这是一个系统字段,将由平台设置,并且由于早期原因(在早期版本的Dynamics CRM中为Customer类型),在parentcustomerid中存在该字段.您只需要在查找字段中指定EntityReference.
newContactProperties.Add("parentcustomerid",new EntityReference("account",new Guid("{accountid guid}"))));
同样也不清楚在"orgReference"字段中使用哪种类型.对于联系人,有效实体类型应为帐户"或联系人".

You don't need to set "parentcustomeridtype" attribute separately. It's a system field, will be set by platform and in parentcustomerid exists for legacy reason, when it was Customer type in earlier versions of Dynamics CRM. You need to specify only EntityReference in lookup field.
newContactProperties.Add("parentcustomerid", new EntityReference("account", new Guid("{accountid guid}")));
Also it's not clear what type you use in "orgReference" field. For contact valid entity types should be "account" or "contact".