【问题标题】:CRM Error When Assigning Lookup Value Incorrect type of attribute value System.Int32分配查找值时出现 CRM 错误 属性值类型不正确 System.Int32
【发布时间】:2014-03-10 14:55:22
【问题描述】:

在 CRM 2011 上,我正在编写一个 C# 来通过读取 .csv 电子表格来创建新帐户。 Account 实体有一个查找字段“Salesperson”,它是针对 CRM“SystemUser”实体的查找值。 “销售人员”字段是一个固定值,所以我只是将 SystemUser Guid 分配给它。但是,在尝试使用 SystemUser Guid 分配此查找值时,出现错误“属性值 System.Int32 的类型不正确”。分配 Guid 值的正确方法是什么?

提前感谢您的帮助。

Uri organizationUri = new Uri("https://mycrm.org.com/crmtest/XRMServices/2011/Organization.svc");
            var cred = new ClientCredentials();
            OrganizationServiceProxy _serviceproxy = new OrganizationServiceProxy(organizationUri, null, cred, null);
            _service = (IOrganizationService)_serviceproxy;
Program p = new Program();

Entity account = new Entity("account");
account.Attributes["salesperson"] = "69ACA8F0-78B9-C211-B753-99E3B511A6F7";
Guid g2 =   p._service.Create(account);

【问题讨论】:

    标签: c# dynamics-crm


    【解决方案1】:

    我不知道您在哪里或如何获得 Incorrect type of attribute value System.Int32 我认为这是代码的子集,即 Program p = new Program(); 正在做,它是如何分配给 _service 的?

    根据 CRM SDK,CRM 2011 的客户实体上没有名为 salesperson (http://msdn.microsoft.com/en-us/library/gg328057.aspx) 的字段。我假设这是您添加到实体的自定义字段,名称应类似于 xxxx_salesperson。查看实体的自定义,找到字段的架构名称。

    接下来,您不能将 Guid 直接分配给查阅字段。您需要分配一个 EntityReference,所以它应该是:

    account.Attributes["salesperson"] = new EntityReference("systemuser", Guid.Parse("69ACA8F0-78B9-C211-B753-99E3B511A6F7"));

    【讨论】:

    • 抱歉延迟回复 - 出于某种原因,我没有收到有关答案的通知。这很好用,谢谢!
    • 如果此答案解决了您的问题,请将其标记为正确答案。您需要单击答案左侧的复选标记。谢谢。
    【解决方案2】:
            Guid guId = _organizationService.Create(foriegnEntity);
    
    
            //Create a collection of the entity ids that will be associated to the contact.
    
            EntityReferenceCollection relatedEntities = new EntityReferenceCollection();
    
            relatedEntities.Add(new EntityReference(foriegnEntity.LogicalName, guId));
    
    
            // Create an object that defines the relationship between entities.
        // RealationshipName is the name of the relationship found in lookup field customization screen for the entity  
    
           Relationship relationship = new Relationship(RelationshipName);
    
    
            //Associate 
            _organizationService.Associate(primaryEntityName, primaryEntityGuid, relationship, relatedEntities);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-11-24
      • 2021-12-24
      • 2019-12-21
      • 2021-11-20
      • 1970-01-01
      • 2021-01-16
      • 1970-01-01
      • 2019-11-07
      相关资源
      最近更新 更多