使用 Web API 创建更新实体定义

发布日期: 2017年1月

适用于: Dynamics 365 (online),Dynamics 365 (on-premises),Dynamics CRM 2016,Dynamics CRM Online

可对模型实体执行可通过组织服务执行的相同操作。 本主题重点介绍如何使用 Web API 处理元数据实体。 要查找有关实体元数据属性的详细信息,请参阅自定义实体元数据EntityMetadata EntityType

在本主题中

创建实体

更新实体

创建属性

创建实体

要创建实体,请将实体数据的 JSON 图形表示POST到 EntityDefinitions 实体集路径。 实体中必须包含其主要名称属性的定义。 不需要为所有属性设置值。 此列表中除了 Description 之外的项目均为必需项目,尽管设置说明是建议的最佳实践。 不指定的属性值将设置为默认值。 若要了解默认值,请参阅在更新实体部分中的示例。 本主题中的示例使用以下实体属性。

实体属性

SchemaName

new_BankAccount

备注

应包含与解决方案发布商匹配的自定义前缀。 此处使用默认值“new_”,但是您应选择适合您的解决方案的前缀。

DisplayName

银行帐户

DisplayCollectionName

银行帐户

Description

用于存储有关客户银行帐户的信息的实体。

OwnershipType

UserOwned

备注

有关您可以在此处设置的值,请参阅 OwnershipTypes EnumType

IsActivity

false

HasActivities

false

HasNotes

false

除上面列出的属性外,EntityMetadataAttributes 属性中还包含一个数组,该数组中包含一个 StringAttributeMetadata EntityType,用于表示实体的主要名称属性。 该属性的 IsPrimaryName 属性必须为 true。 下表介绍此示例中设置的属性。

主要属性属性

SchemaName

new_AccountName

RequiredLevel

None

备注

有关您可以在此处设置的值,请参阅 AttributeRequiredLevelManagedProperty ComplexTypeAttributeRequiredLevel EnumType

MaxLength

100

FormatName

Text

备注

主要名称属性必须使用 Text 格式。 有关其他字符串属性的可用格式选项,请参阅 StringAttributeMetadata 格式

DisplayName

客户名称

Description

键入银行帐户的名称。

IsPrimaryName

true

备注

使用 Label ComplexType 创建或更新标签时,只需设置 LocalizedLabels 属性。 返回的 UserLocalizedLabel 值基于用户的语言首选项,并且为只读。

以下示例显示如何使用属性集创建自定义实体。 语言为英语,使用的区域设置 ID (LCID) 为 1033。可在区域设置 ID (LCID) 图表中找到有效区域设置 ID 值。

  • 请求

    POST cc_WebAPI_ServiceURI/EntityDefinitions HTTP/1.1
    Accept: application/json
    Content-Type: application/json; charset=utf-8
    OData-MaxVersion: 4.0
    OData-Version: 4.0
    
    {
      "@odata.type": "Microsoft.Dynamics.CRM.EntityMetadata",
     "Attributes": [
      {
       "AttributeType": "String",
       "AttributeTypeName": {
        "Value": "StringType"
       },
       "Description": {
         "@odata.type": "Microsoft.Dynamics.CRM.Label",
        "LocalizedLabels": [
         {
           "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
          "Label": "Type the name of the bank account",
          "LanguageCode": 1033
         }
        ]
       },
       "DisplayName": {
         "@odata.type": "Microsoft.Dynamics.CRM.Label",
        "LocalizedLabels": [
         {
           "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
          "Label": "Account Name",
          "LanguageCode": 1033
         }
        ]
       },
       "IsPrimaryName": true,
       "RequiredLevel": {
        "Value": "None",
        "CanBeChanged": true,
        "ManagedPropertyLogicalName": "canmodifyrequirementlevelsettings"
       },
       "SchemaName": "new_AccountName",
        "@odata.type": "Microsoft.Dynamics.CRM.StringAttributeMetadata",
       "FormatName": {
        "Value": "Text"
       },
       "MaxLength": 100
      }
     ],
     "Description": {
       "@odata.type": "Microsoft.Dynamics.CRM.Label",
      "LocalizedLabels": [
       {
         "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
        "Label": "An entity to store information about customer bank accounts",
        "LanguageCode": 1033
       }
      ]
     },
     "DisplayCollectionName": {
       "@odata.type": "Microsoft.Dynamics.CRM.Label",
      "LocalizedLabels": [
       {
         "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
        "Label": "Bank Accounts",
        "LanguageCode": 1033
       }
      ]
     },
     "DisplayName": {
       "@odata.type": "Microsoft.Dynamics.CRM.Label",
      "LocalizedLabels": [
       {
         "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
        "Label": "Bank Account",
        "LanguageCode": 1033
       }
      ]
     },
     "HasActivities": false,
     "HasNotes": false,
     "IsActivity": false,
     "OwnershipType": "UserOwned",
     "SchemaName": "new_BankAccount"
    }
    
  • 响应

    HTTP/1.1 204 No Content
    OData-Version: 4.0
    OData-EntityId: cc_WebAPI_ServiceURI/EntityDefinitions(417129e1-207c-e511-80d2-00155d2a68d2)
    

更新实体

重要

不能使用 HTTP PATCH 方法更新模型实体。 元数据实体包含组织服务 UpdateEntityRequest 的对等服务,用于将该实体定义替换为包含的一个实体定义。 因此,您必须在更新模型实体时使用 HTTP PUT 方法,并且必须谨慎地包含不应更改的所有现有属性。 不能更新单个属性。

使用标签更新元数据实体时,应包括自定义 MSCRM.MergeLabels 标头,以便控制应该在更新中处理多少个标签。 如果项目的标签已经有了其他语言的标签,而您将其替换为仅包含特定语言的一个标签的标签,MSCRM.MergeLabels 标头将控制是覆盖现有标签还是将新标签与任何现有语言标签合并。 如果将 MSCRM.MergeLabels 设置为 true,当语言代码匹配时,定义的任何新标签都将覆盖现有标签。 如果希望覆盖现有标签以仅包含您加入的标签,请将 MSCRM.MergeLabels 设置为 false

重要

如果不加入 MSCRM.MergeLabels 标头,则默认行为类似值为 false,而您的更新中不包含的任何已本地化标签都将丢失。

当您更新实体或属性时,必须在将您所做更改应用于应用程序之前使用 PublishXml ActionPublishAllXml Action。详细信息:发布自定义项

通常,您将向检索属性的 JSON 定义并修改属性,再将其送回。 以下示例中包含 创建实体 示例内创建的实体的所有元数据属性,除了 DisplayName 已更改为“Bank Business Name”。 注意此处的 JSON 为 创建实体 示例中未设置的属性提供默认值,这一点非常有用。

  • 请求

    PUT cc_WebAPI_ServiceURI/EntityDefinitions(417129e1-207c-e511-80d2-00155d2a68d2) HTTP/1.1
    Accept: application/json
    Content-Type: application/json; charset=utf-8
    OData-MaxVersion: 4.0
    OData-Version: 4.0
    MSCRM.MergeLabels: true
    
    {
     "@odata.context": "cc_WebAPI_ServiceURI/$metadata#EntityDefinitions/$entity",
     "ActivityTypeMask": 0,
     "AutoRouteToOwnerQueue": false,
     "CanTriggerWorkflow": true,
     "Description": {
      "LocalizedLabels": [
       {
        "Label": "An entity to store information about customer bank accounts",
        "LanguageCode": 1033,
        "IsManaged": false,
        "MetadataId": "edc3abd7-c5ae-4822-a3ed-51734fdd0469",
        "HasChanged": null
       }
      ]
     },
     "DisplayCollectionName": {
      "LocalizedLabels": [
       {
        "Label": "Bank Accounts",
        "LanguageCode": 1033,
        "IsManaged": false,
        "MetadataId": "7c758e0c-e9cf-4947-93b0-50ec30b20f60",
        "HasChanged": null
       }
      ]
     },
     "DisplayName": {
      "@odata.type": "Microsoft.Dynamics.CRM.Label",
      "LocalizedLabels": [
       {
        "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
        "Label": "Bank Business Name",
        "LanguageCode": 1033
       }
      ]
     },
     "EntityHelpUrlEnabled": false,
     "EntityHelpUrl": null,
     "IsDocumentManagementEnabled": false,
     "IsOneNoteIntegrationEnabled": false,
     "IsInteractionCentricEnabled": false,
     "IsKnowledgeManagementEnabled": false,
     "AutoCreateAccessTeams": false,
     "IsActivity": false,
     "IsActivityParty": false,
     "IsAuditEnabled": {
      "Value": false,
      "CanBeChanged": true,
      "ManagedPropertyLogicalName": "canmodifyauditsettings"
     },
     "IsAvailableOffline": false,
     "IsChildEntity": false,
     "IsAIRUpdated": false,
     "IsValidForQueue": {
      "Value": false,
      "CanBeChanged": true,
      "ManagedPropertyLogicalName": "canmodifyqueuesettings"
     },
     "IsConnectionsEnabled": {
      "Value": false,
      "CanBeChanged": true,
      "ManagedPropertyLogicalName": "canmodifyconnectionsettings"
     },
     "IconLargeName": null,
     "IconMediumName": null,
     "IconSmallName": null,
     "IsCustomEntity": true,
     "IsBusinessProcessEnabled": false,
     "IsCustomizable": {
      "Value": true,
      "CanBeChanged": true,
      "ManagedPropertyLogicalName": "iscustomizable"
     },
     "IsRenameable": {
      "Value": true,
      "CanBeChanged": true,
      "ManagedPropertyLogicalName": "isrenameable"
     },
     "IsMappable": {
      "Value": true,
      "CanBeChanged": false,
      "ManagedPropertyLogicalName": "ismappable"
     },
     "IsDuplicateDetectionEnabled": {
      "Value": false,
      "CanBeChanged": true,
      "ManagedPropertyLogicalName": "canmodifyduplicatedetectionsettings"
     },
     "CanCreateAttributes": {
      "Value": true,
      "CanBeChanged": false,
      "ManagedPropertyLogicalName": "cancreateattributes"
     },
     "CanCreateForms": {
      "Value": true,
      "CanBeChanged": true,
      "ManagedPropertyLogicalName": "cancreateforms"
     },
     "CanCreateViews": {
      "Value": true,
      "CanBeChanged": true,
      "ManagedPropertyLogicalName": "cancreateviews"
     },
     "CanCreateCharts": {
      "Value": true,
      "CanBeChanged": true,
      "ManagedPropertyLogicalName": "cancreatecharts"
     },
     "CanBeRelatedEntityInRelationship": {
      "Value": true,
      "CanBeChanged": true,
      "ManagedPropertyLogicalName": "canberelatedentityinrelationship"
     },
     "CanBePrimaryEntityInRelationship": {
      "Value": true,
      "CanBeChanged": true,
      "ManagedPropertyLogicalName": "canbeprimaryentityinrelationship"
     },
     "CanBeInManyToMany": {
      "Value": true,
      "CanBeChanged": true,
      "ManagedPropertyLogicalName": "canbeinmanytomany"
     },
     "CanEnableSyncToExternalSearchIndex": {
      "Value": true,
      "CanBeChanged": true,
      "ManagedPropertyLogicalName": "canenablesynctoexternalsearchindex"
     },
     "SyncToExternalSearchIndex": false,
     "CanModifyAdditionalSettings": {
      "Value": true,
      "CanBeChanged": true,
      "ManagedPropertyLogicalName": "canmodifyadditionalsettings"
     },
     "CanChangeHierarchicalRelationship": {
      "Value": true,
      "CanBeChanged": true,
      "ManagedPropertyLogicalName": "canchangehierarchicalrelationship"
     },
     "IsOptimisticConcurrencyEnabled": true,
     "ChangeTrackingEnabled": false,
     "IsImportable": true,
     "IsIntersect": false,
     "IsMailMergeEnabled": {
      "Value": true,
      "CanBeChanged": true,
      "ManagedPropertyLogicalName": "canmodifymailmergesettings"
     },
     "IsManaged": false,
     "IsEnabledForCharts": true,
     "IsEnabledForTrace": false,
     "IsValidForAdvancedFind": true,
     "IsVisibleInMobile": {
      "Value": false,
      "CanBeChanged": true,
      "ManagedPropertyLogicalName": "canmodifymobilevisibility"
     },
     "IsVisibleInMobileClient": {
      "Value": false,
      "CanBeChanged": true,
      "ManagedPropertyLogicalName": "canmodifymobileclientvisibility"
     },
     "IsReadOnlyInMobileClient": {
      "Value": false,
      "CanBeChanged": true,
      "ManagedPropertyLogicalName": "canmodifymobileclientreadonly"
     },
     "IsOfflineInMobileClient": {
      "Value": false,
      "CanBeChanged": true,
      "ManagedPropertyLogicalName": "canmodifymobileclientoffline"
     },
     "DaysSinceRecordLastModified": 0,
     "IsReadingPaneEnabled": true,
     "IsQuickCreateEnabled": false,
     "LogicalName": "new_bankaccount",
     "ObjectTypeCode": 10009,
     "OwnershipType": "UserOwned",
     "PrimaryNameAttribute": "new_accountname",
     "PrimaryImageAttribute": null,
     "PrimaryIdAttribute": "new_bankaccountid",
     "Privileges": [
      {
       "CanBeBasic": true,
       "CanBeDeep": true,
       "CanBeGlobal": true,
       "CanBeLocal": true,
       "CanBeEntityReference": false,
       "CanBeParentEntityReference": false,
       "Name": "prvCreatenew_BankAccount",
       "PrivilegeId": "d1a8de4b-27df-42e1-bc5c-b863e002b37f",
       "PrivilegeType": "Create"
      },
      {
       "CanBeBasic": true,
       "CanBeDeep": true,
       "CanBeGlobal": true,
       "CanBeLocal": true,
       "CanBeEntityReference": false,
       "CanBeParentEntityReference": false,
       "Name": "prvReadnew_BankAccount",
       "PrivilegeId": "726043b1-de2c-487e-9d6d-5629fca2bf22",
       "PrivilegeType": "Read"
      },
      {
       "CanBeBasic": true,
       "CanBeDeep": true,
       "CanBeGlobal": true,
       "CanBeLocal": true,
       "CanBeEntityReference": false,
       "CanBeParentEntityReference": false,
       "Name": "prvWritenew_BankAccount",
       "PrivilegeId": "fa50c539-b6c7-4eaf-bd49-fd8224bc51b6",
       "PrivilegeType": "Write"
      },
      {
       "CanBeBasic": true,
       "CanBeDeep": true,
       "CanBeGlobal": true,
       "CanBeLocal": true,
       "CanBeEntityReference": false,
       "CanBeParentEntityReference": false,
       "Name": "prvDeletenew_BankAccount",
       "PrivilegeId": "17c1fd6e-f856-45e7-b563-796f53108b85",
       "PrivilegeType": "Delete"
      },
      {
       "CanBeBasic": true,
       "CanBeDeep": true,
       "CanBeGlobal": true,
       "CanBeLocal": true,
       "CanBeEntityReference": false,
       "CanBeParentEntityReference": false,
       "Name": "prvAssignnew_BankAccount",
       "PrivilegeId": "133ca81d-668e-4c19-a71e-10c6dfe099cd",
       "PrivilegeType": "Assign"
      },
      {
       "CanBeBasic": true,
       "CanBeDeep": true,
       "CanBeGlobal": true,
       "CanBeLocal": true,
       "CanBeEntityReference": false,
       "CanBeParentEntityReference": false,
       "Name": "prvSharenew_BankAccount",
       "PrivilegeId": "15f27df4-9c67-47c9-b1f1-274e1c44f24a",
       "PrivilegeType": "Share"
      },
      {
       "CanBeBasic": true,
       "CanBeDeep": true,
       "CanBeGlobal": true,
       "CanBeLocal": true,
       "CanBeEntityReference": false,
       "CanBeParentEntityReference": false,
       "Name": "prvAppendnew_BankAccount",
       "PrivilegeId": "ac8b1920-8f93-4e9d-94e3-c680e2a2f228",
       "PrivilegeType": "Append"
      },
      {
       "CanBeBasic": true,
       "CanBeDeep": true,
       "CanBeGlobal": true,
       "CanBeLocal": true,
       "CanBeEntityReference": false,
       "CanBeParentEntityReference": false,
       "Name": "prvAppendTonew_BankAccount",
       "PrivilegeId": "f63a5f46-3bc7-4eac-81d0-7f77f566ef46",
       "PrivilegeType": "AppendTo"
      }
     ],
     "RecurrenceBaseEntityLogicalName": null,
     "ReportViewName": "Filterednew_BankAccount",
     "SchemaName": "new_BankAccount",
     "IntroducedVersion": "1.0",
     "IsStateModelAware": true,
     "EnforceStateTransitions": false,
     "EntityColor": null,
     "LogicalCollectionName": "new_bankaccounts",
     "CollectionSchemaName": "new_BankAccounts",
     "EntitySetName": "new_bankaccounts",
     "IsEnabledForExternalChannels": false,
     "IsPrivate": false,
     "MetadataId": "417129e1-207c-e511-80d2-00155d2a68d2",
     "HasChanged": null
    }
    
  • 响应

    HTTP/1.1 204 No Content
    OData-Version: 4.0
    

创建属性

您可以在创建实体的同时创建属性,方法是除了充当主要名称属性的字符串属性之外,还向您发布的实体的 Attributes 数组中添加属性的 JSON 定义。 如果要向已创建的实体添加属性,可以将包含这些属性的 JSON 定义的 POST 请求发送给实体 Attributes 集合值导航属性。

创建字符串属性

以下示例将使用这些属性创建字符串属性。

字符串属性

SchemaName

new_BankName

DisplayName

银行名称

Description

键入银行的名称。

RequiredLevel

None

MaxLength

100

FormatName

Text

以下示例使用属性创建字符串属性,并将其添加到 MetadataId 值为 402fa40f-287c-e511-80d2-00155d2a68d2 的实体。 属性的 URI 在响应中返回。

  • 请求

    POST cc_WebAPI_ServiceURI/EntityDefinitions(402fa40f-287c-e511-80d2-00155d2a68d2)/Attributes HTTP/1.1
    Accept: application/json
    Content-Type: application/json; charset=utf-8
    OData-MaxVersion: 4.0
    OData-Version: 4.0
    
    {
     "AttributeType": "String",
     "AttributeTypeName": {
      "Value": "StringType"
     },
     "Description": {
      "@odata.type": "Microsoft.Dynamics.CRM.Label",
      "LocalizedLabels": [
       {
        "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
        "Label": "Type the name of the bank",
        "LanguageCode": 1033
       }
      ]
     },
     "DisplayName": {
      "@odata.type": "Microsoft.Dynamics.CRM.Label",
      "LocalizedLabels": [
       {
        "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
        "Label": "Bank Name",
        "LanguageCode": 1033
       }
      ]
     },
     "RequiredLevel": {
      "Value": "None",
      "CanBeChanged": true,
      "ManagedPropertyLogicalName": "canmodifyrequirementlevelsettings"
     },
     "SchemaName": "new_BankName",
     "@odata.type": "Microsoft.Dynamics.CRM.StringAttributeMetadata",
     "FormatName": {
      "Value": "Text"
     },
     "MaxLength": 100
    }
    
  • 响应

    HTTP/1.1 204 No Content
    OData-Version: 4.0
    OData-EntityId: cc_WebAPI_ServiceURI/EntityDefinitions(402fa40f-287c-e511-80d2-00155d2a68d2)/Attributes(f01bef16-287c-e511-80d2-00155d2a68d2)
    

创建货币属性

以下示例将使用这些属性创建货币属性。

货币属性

SchemaName

new_Balance

DisplayName

余额

Description

输入余额。

RequiredLevel

None

PrecisionSource

2

备注

有关 PrecisionSource 的有效值的信息,请参阅数量数据属性。 值 2 表示小数精度级别匹配与当前记录关联的 TransactionCurrency.CurrencyPrecision。

以下示例使用属性创建货币属性,并将其添加到 MetadataId 值为 402fa40f-287c-e511-80d2-00155d2a68d2 的实体。 属性的 URI 在响应中返回。

  • 请求

    POST cc_WebAPI_ServiceURI/EntityDefinitions(402fa40f-287c-e511-80d2-00155d2a68d2)/Attributes HTTP/1.1
    Accept: application/json
    Content-Type: application/json; charset=utf-8
    OData-MaxVersion: 4.0
    OData-Version: 4.0
    
    {
     "AttributeType": "Money",
     "AttributeTypeName": {
      "Value": "MoneyType"
     },
     "Description": {
      "@odata.type": "Microsoft.Dynamics.CRM.Label",
      "LocalizedLabels": [
       {
        "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
        "Label": "Enter the balance amount",
        "LanguageCode": 1033
       }
      ]
     },
     "DisplayName": {
      "@odata.type": "Microsoft.Dynamics.CRM.Label",
      "LocalizedLabels": [
       {
        "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
        "Label": "Balance",
        "LanguageCode": 1033
       }
      ]
     },
     "RequiredLevel": {
      "Value": "None",
      "CanBeChanged": true,
      "ManagedPropertyLogicalName": "canmodifyrequirementlevelsettings"
     },
     "SchemaName": "new_Balance",
     "@odata.type": "Microsoft.Dynamics.CRM.MoneyAttributeMetadata",
     "PrecisionSource": 2
    }
    
  • 响应

    HTTP/1.1 204 No Content
    OData-Version: 4.0
    OData-EntityId: cc_WebAPI_ServiceURI/EntityDefinitions(402fa40f-287c-e511-80d2-00155d2a68d2)/Attributes(f11bef16-287c-e511-80d2-00155d2a68d2)
    

创建日期时间属性。

以下示例将使用这些属性创建日期时间属性。

日期时间属性

SchemaName

new_Checkeddate

DisplayName

日期

Description

上次确认科目余额的日期。

RequiredLevel

无​​

Format

DateOnly

备注

有关该属性的有效选项,请参阅 DateTimeFormat EnumType

以下示例使用属性创建日期时间属性,并将其添加到 MetadataId 值为 402fa40f-287c-e511-80d2-00155d2a68d2 的实体。 属性的 URI 在响应中返回。

  • 请求

    POST cc_WebAPI_ServiceURI/EntityDefinitions(402fa40f-287c-e511-80d2-00155d2a68d2)/Attributes HTTP/1.1
    Accept: application/json
    Content-Type: application/json; charset=utf-8
    OData-MaxVersion: 4.0
    OData-Version: 4.0
    
    {
     "AttributeType": "DateTime",
     "AttributeTypeName": {
      "Value": "DateTimeType"
     },
     "Description": {
      "@odata.type": "Microsoft.Dynamics.CRM.Label",
      "LocalizedLabels": [
       {
        "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
        "Label": "The date the account balance was last confirmed",
        "LanguageCode": 1033
       }
      ]
     },
     "DisplayName": {
      "@odata.type": "Microsoft.Dynamics.CRM.Label",
      "LocalizedLabels": [
       {
        "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
        "Label": "Date",
        "LanguageCode": 1033
       }
      ]
     },
     "RequiredLevel": {
      "Value": "None",
      "CanBeChanged": true,
      "ManagedPropertyLogicalName": "canmodifyrequirementlevelsettings"
     },
     "SchemaName": "new_Checkeddate",
     "@odata.type": "Microsoft.Dynamics.CRM.DateTimeAttributeMetadata",
     "Format": "DateOnly"
    }
    
  • 响应

    HTTP/1.1 204 No Content
    OData-Version: 4.0
    OData-EntityId: cc_WebAPI_ServiceURI/EntityDefinitions(402fa40f-287c-e511-80d2-00155d2a68d2)/Attributes(fe1bef16-287c-e511-80d2-00155d2a68d2)
    

创建客户查找属性

与其他属性不同,客户查找标记是使用 CreateCustomerRelationships 操作创建的。 此操作的参数需要查找属性的定义和一对一对多关系。 客户查找属性有两种一对多关系:一个对客户实体,另一个对联系人实体。

以下示例将使用这些属性创建客户查找属性。

客户查找属性属性

SchemaName

new_CustomerId

DisplayName

客户

Description

示例客户查找属性

此示例创建客户查找属性 new_CustomerId 并将其添加到自定义实体:new_bankaccount。 响应是 CreateCustomerRelationshipsResponse 复杂类型。

  • Request

    POST 
          [组织 URI]/api/data/v8.2/CreateCustomerRelationships HTTP/1.1
    OData-MaxVersion: 4.0
    OData-Version: 4.0
    Accept: application/json
    Content-Type: application/json; charset=utf-8
    
    {
        "OneToManyRelationships": [{
            "SchemaName": "new_bankaccount_customer_account",
            "ReferencedEntity": "account",
            "ReferencingEntity": "new_bankaccount"
        }, {
            "SchemaName": "new_bankaccount_customer_contact",
            "ReferencedEntity": "contact",
            "ReferencingEntity": "new_bankaccount"
        }],
        "Lookup": {
            "AttributeType": "Lookup",
            "AttributeTypeName": {
                "Value": "LookupType"
            },
            "Description": {
                "@odata.type": "Microsoft.Dynamics.CRM.Label",
                "LocalizedLabels": [{
                    "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
                    "Label": "Sample Customer Lookup Attribute",
                    "LanguageCode": 1033
                }],
                "UserLocalizedLabel": {
                    "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
                    "Label": "Sample Customer Lookup Attribute",
                    "LanguageCode": 1033
                }
            },
            "DisplayName": {
                "@odata.type": "Microsoft.Dynamics.CRM.Label",
                "LocalizedLabels": [{
                    "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
                    "Label": "Customer",
                    "LanguageCode": 1033
                }],
                "UserLocalizedLabel": {
                    "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
                    "Label": "Customer",
                    "LanguageCode": 1033
                }
            },
            "SchemaName": "new_CustomerId",
            "@odata.type": "Microsoft.Dynamics.CRM.ComplexLookupAttributeMetadata"
        }
    }
    
  • Response

    HTTP/1.1 200 OK
    Content-Type: application/json; odata.metadata=minimal
    OData-Version: 4.0
    
    {
        "@odata.context": "
          [组织 URI]/api/data/v8.2/$metadata#Microsoft.Dynamics.CRM.CreateCustomerRelationshipsResponse",
        "RelationshipIds": [
            "a7d261bc-3580-e611-80d7-00155d2a68de", "aed261bc-3580-e611-80d7-00155d2a68de"
        ],
        "AttributeId": "39a5d94c-e8a2-4a41-acc0-8487242d455e"
    }
    

更新属性

按照更新实体中的说明,模型实体使用 HTTP PUT 方法和当前项目的整个 JSON 定义更新。 这适用于属性和实体。 就像处理实体,您也可以选择使用将值设置为 falseMSCRM.MergeLabels 标头覆盖标签,并且自定义必须先发布,才会在系统中激活。

另请参阅

使用具有 Dynamics 365 元数据的 Web API
使用 Web API 查询元数据
按名称或 MetadataId 检索元数据
使用 Web API 创建和更新实体关系
使用含有 Dynamics 365 元数据的组织服务
自定义实体属性元数据

Microsoft Dynamics 365

© 2017 Microsoft。 保留所有权利。 版权