【发布时间】:2014-12-09 07:56:45
【问题描述】:
各位聪明的开发者们,
我想通过 Web 服务在 Microsoft Dynamics CRM 2013 中创建属于某个组织的联系人时遇到问题
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'
我很困惑为什么会发生这种情况以及如何解决这个问题。如果可以,请帮助我。
谢谢你, AllWorkNoPlay
【问题讨论】:
-
organizationType 的值是否设置正确?像下面这样: OptionSetValue organizationType = new OptionSetValue(1);如果父客户是客户,则该值为 1,如果是联系人,则该值为 2。
-
您不需要设置 fullname 和 parentcustomeridtype 属性,确保 orgReference 包含父记录的正确逻辑名称
-
即使有您的有用提示,我也无法摆脱此错误消息。我现在尝试使用 xrmearlyboundgenerator.codeplex.com 使用“早期绑定”对象来完成我想要的。创建帐户和联系人有效,现在我正在尝试使用 OrganizationServiceContext 的 AttachLink 方法...待续
标签: web-services crm dynamics-crm-2013