【问题标题】:How to add a new entity to MS CRM如何向 MS CRM 添加新实体
【发布时间】:2014-12-11 09:41:03
【问题描述】:

我想在 crm 中创建一个新实体

    OrganizationService_orgService ;
    var connection = CrmConnection.Parse(conn);
    _orgService = new OrganizationService(connection);

    Entity newEntity = new Entity("this_is_a_new_entity");
    Guid newEntityID = _orgService.Create(newEntity); 

我写了上面的代码,其中conn是格式正确的连接字符串(我检查过)

  string conn = "Url=https://damnidiot.crm5.dynamics.com; Username=XXXXXXXX@damnidiot.onmicrosoft.com; Password=XXXXXXXXX;";

但是当我运行代码时出现异常{"The entity with a name = 'this_is_a_new_entity' was not found in the MetadataCache."}

我假设我收到此错误是因为我的 crm 没有实体 this_is_a_new_entity 的定义。

是否可以检索和更新我的 MS CRM 的元数据缓存?(我正在使用 Microsoft Dynamics CRM 2013)

【问题讨论】:

  • 该实体是否存在于 mscrm 中?
  • 不,MSCRM 中不存在该实体

标签: dynamics-crm-2011 dynamics-crm crm dynamics-crm-2013


【解决方案1】:

如果你使用new Entity("new_entity_name"),你是在告诉代码你想在名为new_entity_name已经存在的实体中创建一个新的记录

要完全创建一个新实体,您必须发出CreateEntityRequest (link to MSDN)

// PART OF THE LINKED SAMPLE
CreateEntityRequest createrequest = new CreateEntityRequest
{
    //Define the entity
    Entity = new EntityMetadata
    {
        SchemaName = _customEntityName,
        DisplayName = new Label("Bank Account", 1033),
        DisplayCollectionName = new Label("Bank Accounts", 1033),
        Description = new Label("An entity to store information about customer bank accounts", 1033),
        OwnershipType = OwnershipTypes.UserOwned,
        IsActivity = false,

    },

    // Define the primary attribute for the entity
    PrimaryAttribute = new StringAttributeMetadata
    {
        SchemaName = "new_accountname",
        RequiredLevel = new AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None),
        MaxLength = 100,
        Format = StringFormat.Text,
        DisplayName = new Label("Account Name", 1033),
        Description = new Label("The primary attribute for the Bank Account entity.", 1033)
    }

};

【讨论】:

    【解决方案2】:

    要创建新实体,您应该使用Create Entity Request。您的代码创建了 this_is_a_new_entity 的记录

    【讨论】:

    • @user4137130 抱歉,我不明白您所说的实体层次结构是什么意思。在您的情况下,在 CRM 中创建实体等于在数据库中创建表,而您的代码尝试在不存在的表中创建记录。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多