【问题标题】:MS CRM 2013 Attribute parentcustomeridtype must not be NULL if attribute parentcustomerid is not NULL如果属性 parentcustomerid 不为 NULL,则 MS CRM 2013 属性 parentcustomeridtype 不得为 NULL
【发布时间】: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


【解决方案1】:

您不需要单独设置“parentcustomeridtype”属性。它是一个系统字段,将由平台设置,并且在 parentcustomerid 中由于遗留原因而存在,当它是早期版本的 Dynamics CRM 中的客户类型时。 您只需在查找字段中指定 EntityReference。
newContactProperties.Add("parentcustomerid", new EntityReference("account", new Guid("{accountid guid}")));
此外,还不清楚您在“orgReference”字段中使用什么类型。对于联系人,有效实体类型应为“帐户”或“联系人”。

【讨论】:

  • 感谢您的反应。无论我是否设置 parentcustomeridtype 都没有关系,我总是会收到这个错误。 OrgReference 包含对帐户的有效 EntityReference。
【解决方案2】:

感谢您的回答,我没有设法通过这种方式使用网络服务来解决问题。

我尝试使用 Early Bound 访问成功:

  1. 使用https://xrmearlyboundgenerator.codeplex.com/ 生成的代理对象
  2. 在 assemblyInfo 中添加了行 [assembly: Microsoft.Xrm.Sdk.Client.ProxyTypesAssemblyAttribute()] 以使 Intellisense 可用(即使对于自定义字段)
  3. 现在我设法创建一个联系人并将其分配给一个组织(类似这样):

        var contact = new Contact()
                       {
                           FirstName = "Bob",
                           LastName = "Dobalina",
                           Address1_Line1 = "123 Strasse",
                           Address1_City = "Berlin",
                           Address1_PostalCode = "32254",
                           Telephone1 = "425-555-5678",
                           EMailAddress1 = "bob.dobalina@germany.de"
                       };
    
        var account = new Account()
        {
            Name = "Siemens Germany",
        };
    
    
        context.AddObject(contact);
        context.AddObject(account);
    
        context.AddLink(account, "contact_customer_accounts", contact);
    
        context.SaveChanges();
    }
    

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-10
    • 1970-01-01
    • 1970-01-01
    • 2017-08-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多