Condividi tramite


Creare e aggiornare definizioni di entità tramite la Web API

 

Data di pubblicazione: gennaio 2017

Si applica a: Dynamics 365 (online), Dynamics 365 (on-premises), Dynamics CRM 2016, Dynamics CRM Online

È possibile eseguire tutte le stesse operazioni sulle entità modello che è possibile eseguire con il servizio dell'organizzazione. Questo argomento è incentrato sull'utilizzo delle entità metadati tramite la Web API. Per i dettagli sulle proprietà dei metadati di entità, vedere Personalizzare i metadati dell'entità e EntityMetadata EntityType.

In questo argomento

Creare entità

Aggiornare entità

Creare attributi

Creare entità

Per creare un'entità, eseguire il POST della rappresentazione JSON dei dati dell'entità nel percorso del set di entità EntityDefinitions. Un'entità deve includere la definizione dell'attributo nome primario per l'entità. Non è necessario impostare i valori per tutte le proprietà. Gli elementi in questo elenco, tranne Description, sono obbligatori, sebbene impostare una descrizione sia una procedura consigliata. I valori di proprietà non specificati verranno impostati sui valori predefiniti. Per comprendere i valori predefiniti, guarda l'esempio nella sezione Aggiornare entità. L'esempio in questo argomento utilizza le proprietà di entità seguenti.

Proprietà di entità

Valore

SchemaName

new_BankAccount

Nota

È necessario includere il prefisso di personalizzazione che corrisponde all'autore di soluzioni. Qui viene usato il valore predefinito "new_", ma è necessario scegliere il prefisso che funziona per la tua soluzione.

DisplayName

Conto bancario

DisplayCollectionName

Conti bancari

Description

Un'entità per archiviare informazioni sui conti bancari dei clienti.

OwnershipType

UserOwned

Nota

Per i valori che è possibile impostare qui, vedere OwnershipTypes EnumType.

IsActivity

false

HasActivities

false

HasNotes

false

Oltre alle proprietà elencate in precedenza, la proprietà EntityMetadataAttributes deve contenere una matrice che include un StringAttributeMetadata EntityType per rappresentare l'attributo nome primario per l'entità. La proprietà IsPrimaryName dell'attributo deve essere true. Nella tabella seguente vengono descritte le proprietà impostate nell'esempio.

Proprietà attributo primario

Valore

SchemaName

new_AccountName

RequiredLevel

None

Nota

Per i valori che è possibile impostare qui, vedere AttributeRequiredLevelManagedProperty ComplexType e AttributeRequiredLevel EnumType.

MaxLength

100

FormatName

Text

Nota

L'attributo nome primario deve usare il formato Text. Per le opzioni di formattazione disponibili per altri attributi stringa, vedere Formati di StringAttributeMetadata.

DisplayName

Nome account

Description

Digitare il nome del conto bancario.

IsPrimaryName

true

Nota

Quando si creano o aggiornano le etichette con Label ComplexType, è sufficiente impostare la proprietà LocalizedLabels. Il valore UserLocalizedLabel restituito è basato la preferenza della lingua dell'utente ed è di sola lettura.

Il seguente esempio mostra la creazione di un'entità personalizzata con le proprietà impostate. La lingua è l'inglese, con l'ID impostazioni locali (LCID) 1033.Valori LCID (ID impostazioni locali) validi sono disponibili alla pagina Grafico LCID (impostazioni ID locali).

  • Richiesta

    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"
    }
    
  • Risposta

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

Aggiornare entità

Importante

Non è possibile utilizzare il metodo HTTP PATCH per aggiornare le entità modello. Le entità metadati hanno parità con il servizio dell'organizzazione UpdateEntityRequest che sostituisce la definizione di entità con quella inclusa. Pertanto, è necessario utilizzare il metodo HTTP PUT quando si aggiornano le entità modello, facendo attenzione a includere tutte le proprietà esistenti che non si intende modificare. Non puoi aggiornare proprietà individuali.

Quando si aggiornano le entità metadati con le etichette, è necessario includere un'intestazione MSCRM.MergeLabels personalizzata per definire come gestire le etichette nell'aggiornamento. Se un'etichetta per un elemento ha già etichette per altre lingue e la si aggiorna con un'etichetta contenente solo un'etichetta per una lingua specifica, l'intestazione MSCRM.MergeLabels determina se sovrascrivere le etichette esistenti o unire la nuova etichetta con eventuali etichette esistenti di lingua. Con MSCRM.MergeLabels impostato su true, tutte le nuove etichette definite sovrascriveranno le etichette esistenti solo quando il codice della lingua corrisponde. Se desideri sovrascrivere le etichette esistenti per includere solo le etichette scelte da te, imposta MSCRM.MergeLabels su false.

Importante

Se non includi un'intestazione MSCRM.MergeLabels, il comportamento predefinito sarà come se il valore fosse false e le etichette localizzate non incluse nell'aggiornamento verranno perse.

Quando si aggiorna un'entità o un attributo, è necessario utilizzare PublishXml Action o PublishAllXml Action prima che le modifiche operate vengano applicate all'applicazione.Ulteriori informazioni:Pubblicare personalizzazioni

In genere recupererai la definizione JSON dell'attributo e modificherai le proprietà prima di reinviarla. L'esempio seguente contiene tutte le proprietà dei metadati dell'entità create nell'esempio Creare entità, ma con DisplayName modificato in "Bank Business Name". Può essere utile notare che il codice JSON qui fornisce i valori predefiniti per le proprietà non impostati nell'esempio Creare entità.

  • Richiesta

    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
    }
    
  • Risposta

    HTTP/1.1 204 No Content
    OData-Version: 4.0
    

Creare attributi

È possibile creare attributi comtemporaneamente all'entità includendo la definizione JSON degli attributi nella matrice Attributes per l'entità inserita oltre all'attributo stringa che funge come attributo nome primario. Se desidera aggiungere attributi a un'entità già creata, è possibile inviare una richiesta POST includendo la relativa definizione JSON nella proprietà di navigazione con valori di raccolta Attributes.

Creare un attributo stringa

Il seguente esempio utilizza queste proprietà per creare un attributo stringa.

Proprietà di attributo stringa

Valori

SchemaName

new_BankName

DisplayName

Nome banca

Description

Digitare il nome della banca.

RequiredLevel

None

MaxLength

100

FormatName

Text

L'esempio seguente crea un attributo stringa utilizzando le proprietà e lo aggiunge all'entità con il valore MetadataId di 402fa40f-287c-e511-80d2-00155d2a68d2. L'URI per l'attributo viene restituito nella risposta.

  • Richiesta

    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
    }
    
  • Risposta

    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)
    

Creare un attributo di tipo money

Il seguente esempio utilizza queste proprietà per creare un attributo di tipo money.

Proprietà di attributo di tipo money

Valori

SchemaName

new_Balance

DisplayName

Saldo

Description

Immettere l'importo del saldo.

RequiredLevel

None

PrecisionSource

2

Nota

Per informazioni sui valori validi di PrecisionSource, vedere la pagina Attributi dati di quantità. Il valore 2 significa che il livello di precisione decimale corrisponderà all'oggetto TransactionCurrency.CurrencyPrecision associato al record corrente.

L'esempio seguente crea un attributo di tipo money utilizzando le proprietà e lo aggiunge all'entità con il valore MetadataId di 402fa40f-287c-e511-80d2-00155d2a68d2. L'URI per l'attributo viene restituito nella risposta.

  • Richiesta

    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
    }
    
  • Risposta

    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)
    

Creare un attributo di tipo datetime

Il seguente esempio utilizza queste proprietà per creare un attributo di tipo datetime.

Proprietà di attributo di tipo datetime

Valori

SchemaName

new_Checkeddate

DisplayName

Data

Description

La data in cui il saldo del conto è stato confermato l'ultima volta.

RequiredLevel

Nessuna

Format

DateOnly

Nota

Per le opzioni valide per questa proprietà, vedere DateTimeFormat EnumType.

L'esempio seguente crea un attributo di tipo datetime utilizzando le proprietà e lo aggiunge all'entità con il valore MetadataId di 402fa40f-287c-e511-80d2-00155d2a68d2. L'URI per l'attributo viene restituito nella risposta.

  • Richiesta

    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"
    }
    
  • Risposta

    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)
    

Creare un attributo di tipo lookup cliente

Diversamente da altri attributi, un attributo di tipo lookup del cliente viene creato utilizzando l'azione CreateCustomerRelationships. I parametri per questa azione richiedono la definizione dell'attributo di tipo lookup e un paio di relazioni uno-a-molti. Un attributo di tipo lookup del cliente ha due relazioni uno-a-molti: una per l'entità account e l'altra per l'entità contatto.

Il seguente esempio utilizza queste proprietà per creare un attributo di tipo lookup del cliente.

Proprietà dell'attributo di tipo lookup del cliente

Valori

SchemaName

new_CustomerId

DisplayName

Cliente

Description

Esempio di attributo di tipo lookup del cliente

L'esempio crea un attributo di tipo lookup del cliente new_CustomerId e lo aggiunge all'entità personalizzata: new_bankaccount. La risposta è un tipo complesso CreateCustomerRelationshipsResponse.

  • Request

    POST 
          [URI organizzazione]/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 organizzazione]/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"
    }
    

Aggiornare un attributo

Come menzionato in Aggiornare entità, le entità modello vengono aggiornate utilizzando il metodo HTTP PUT con l'intera definizione JSON dell'elemento corrente. Ciò si applica agli attributi e alle entità. Proprio come con le entità, è possibile sovrascrivere le etichette usando l'intestazione MSCRM.MergeLabels con il valore impostato su false ed è necessario pubblicare le personalizzazioni prima che diventino attive nel sistema.

Vedere anche

Utilizzare l'API Web con i metadati di Dynamics 365
Query sui metadati tramite la Web API
Recuperare i metadati per nome o MetadataId
Creare e aggiornare relazioni di entità tramite l'API Web
Utilizzare il servizio Organizzazione con i metadati di Dynamics 365
Personalizzare i metadati degli attributi di entità

Microsoft Dynamics 365

© 2017 Microsoft. Tutti i diritti sono riservati. Copyright