共用方式為


使用 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 值會根據使用者的語言喜好設定,並且是唯讀的。

下列範例示範建立已設定屬性的自訂實體。 語言是英文,使用地區設定識別碼 (LCID) 1033。您可以在地區設定識別碼 (LCID) 表找到有效的地區設定識別碼值。

  • 要求

    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
    

建立屬性

您可以在建立實體的同時建立屬性,除了做為主要名稱屬性的字串屬性之外,另外包含實體的 JSON 定義在您張貼的實體的 Attributes 陣列中即可。 若要新增屬性至已建立的實體,您可以傳送 POST 要求 (包括它們的 JSON 定義) 至實體 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 定義更新。 這適用於屬性以及實體。 就像其他實體一樣,您可以選擇覆寫標籤,使用 MSCRM.MergeLabels 標題並將值設為 false,而且您必須發行自訂,以便在系統中生效。

另請參閱

使用 Web API 搭配 Dynamics 365 中繼資料
使用 Web API 查詢中繼資料
依名稱或 MetadataId 擷取中繼資料
使用 Web API 建立和更新實體關聯
搭配使用組織服務與 Dynamics 365 中繼資料
自訂實體屬性中繼資料

Microsoft Dynamics 365

© 2017 Microsoft. 著作權所有,並保留一切權利。 著作權