Partager via


Créer et mettre à jour des définitions de colonnes à l’aide de l’API web

Vous pouvez effectuer toutes les mêmes opérations sur les définitions de colonnes à l’aide de l’API web que vous pouvez avec le SDK pour .NET. Cet article se concentre sur l’utilisation des définitions de colonnes (métadonnées) à l’aide de l’API web.

Créer des colonnes

Vous pouvez créer des colonnes de table (attributs d’entité) en même temps que vous créez la définition de table en incluant la définition JSON des attributs dans le Attributes tableau pour l’entité que vous publiez en plus de l’attribut de chaîne qui sert d’attribut de nom principal. Si vous souhaitez ajouter des attributs à une entité déjà créée, vous pouvez envoyer une POST requête incluant la définition JSON de ces attributs à la propriété de navigation de collection d’entités Attributes .

Les exemples suivants montrent comment créer différents types de colonnes

Créer une colonne de chaîne

L’exemple suivant utilise ces propriétés pour créer une colonne de chaîne.

Propriétés "StringAttributeMetadata" Valeurs
SchemaName new_BankName
DisplayName Nom de la banque
Description Tapez le nom de la banque.
RequiredLevel None
MaxLength 100
FormatName Text

L’exemple suivant crée une colonne de chaîne à l’aide des propriétés et l’ajoute à la sample_bankaccount table.

L’URI de l’attribut est retourné dans la réponse.

Requête :

POST [Organization URI]/api/data/v9.2/EntityDefinitions(LogicalName='sample_bankaccount')/Attributes HTTP/1.1
MSCRM.SolutionUniqueName: examplesolution
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  
}  
  

Réponse:

HTTP/1.1 204 No Content  
OData-Version: 4.0  
OData-EntityId: [Organization URI]/api/data/v9.2/EntityDefinitions(LogicalName='sample_bankaccount')/Attributes(00aa00aa-bb11-cc22-dd33-44ee44ee44ee)  

Créer une colonne d’argent

L’exemple suivant utilise ces propriétés pour créer un attribut monétaire.

Propriétés de MoneyAttributeMetadata Valeurs
SchemaName new_Balance
DisplayName Solde
Description Entrez le montant du solde.
RequiredLevel Aucun
PrecisionSource 2
Note: Pour plus d’informations sur les valeurs valides pour PrecisionSource, consultez MoneyType. La valeur 2 signifie que le niveau de précision décimale correspond à TransactionCurrency.CurrencyPrecision associé à l’enregistrement actif.

L’exemple suivant crée un attribut money à l’aide des propriétés et l’ajoute à la sample_bankaccount table. L’URI de l’attribut est retourné dans la réponse.

Requête :

POST [Organization URI]/api/data/v9.2/EntityDefinitions(LogicalName='sample_bankaccount')/Attributes HTTP/1.1
MSCRM.SolutionUniqueName: examplesolution
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  
}  

Réponse:

HTTP/1.1 204 No Content  
OData-Version: 4.0  
OData-EntityId: [Organization URI]/api/data/v9.2/EntityDefinitions(LogicalName='sample_bankaccount')/Attributes(11bb11bb-cc22-dd33-ee44-55ff55ff55ff)  

Créer une colonne datetime

L’exemple suivant utilise ces propriétés pour créer un attribut datetime.

Propriétés DateTimeAttributeMetadata Valeurs
SchemaName new_Checkeddate
DisplayName Date
Description Date de la dernière confirmation du solde du compte.
RequiredLevel None
Format DateOnly Note: Pour connaître les options valides pour cette propriété, consultez DateTimeFormat EnumType

L’exemple suivant crée un attribut datetime à l’aide des propriétés et l’ajoute à la sample_bankaccount table. L’URI de l’attribut est retourné dans la réponse.

Requête :

POST [Organization URI]/api/data/v9.2/EntityDefinitions(LogicalName='sample_bankaccount')/Attributes HTTP/1.1
MSCRM.SolutionUniqueName: examplesolution
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"  
}  

Réponse:

HTTP/1.1 204 No Content  
OData-Version: 4.0  
OData-EntityId: [Organization URI]/api/data/v9.2/EntityDefinitions(LogicalName='sample_bankaccount')/Attributes(22cc22cc-dd33-ee44-ff55-66aa66aa66aa)  

Créer une colonne booléenne

L’exemple suivant utilise ces propriétés pour créer une colonne booléenne.

Propriétés de BooleanAttributeMetadata Valeurs
SchemaName new_Boolean
DisplayName Exemple booléen
Description Attribut booléen
RequiredLevel None
OptionSet.TrueOption Vrai
OptionSet.FalseOption Faux

L’exemple suivant crée un attribut booléen à l’aide des propriétés et l’ajoute à l’entité avec la LogicalName valeur de new_bankaccount. L’URI de l’attribut est retourné dans la réponse.

Requête :

POST [Organization Uri]/api/data/v9.2/EntityDefinitions(LogicalName='new_bankaccount')/Attributes HTTP/1.1
MSCRM.SolutionUniqueName: examplesolution
OData-MaxVersion: 4.0
OData-Version: 4.0
If-None-Match: null
Accept: application/json

{
  "@odata.type": "Microsoft.Dynamics.CRM.BooleanAttributeMetadata",
  "AttributeType": "Boolean",
  "AttributeTypeName": {
    "Value": "BooleanType"
  },
  "DefaultValue": false,
  "OptionSet": {
    "TrueOption": {
      "Value": 1,
      "Label": {
        "@odata.type": "Microsoft.Dynamics.CRM.Label",
        "LocalizedLabels": [
          {
            "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
            "Label": "True",
            "LanguageCode": 1033,
            "IsManaged": false
          }
        ]
      }
    },
    "FalseOption": {
      "Value": 0,
      "Label": {
        "@odata.type": "Microsoft.Dynamics.CRM.Label",
        "LocalizedLabels": [
          {
            "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
            "Label": "False",
            "LanguageCode": 1033,
            "IsManaged": false
          }
        ]
      }
    },
    "OptionSetType": "Boolean"
  },
  "Description": {
    "@odata.type": "Microsoft.Dynamics.CRM.Label",
    "LocalizedLabels": [
      {
        "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
        "Label": "Boolean Attribute",
        "LanguageCode": 1033,
        "IsManaged": false
      }
    ]
  },
  "DisplayName": {
    "@odata.type": "Microsoft.Dynamics.CRM.Label",
    "LocalizedLabels": [
      {
        "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
        "Label": "Sample Boolean",
        "LanguageCode": 1033,
        "IsManaged": false
      }
    ]
  },
  "RequiredLevel": {
    "Value": "None",
    "CanBeChanged": false,
    "ManagedPropertyLogicalName": "canmodifyrequirementlevelsettings"
  },
  "SchemaName": "new_Boolean"
}

Réponse:

HTTP/1.1 NoContent
OData-Version: 4.0
OData-EntityId: [Organization Uri]/api/data/v9.2/EntityDefinitions(LogicalName='new_bankaccount')/Attributes(33dd33dd-ee44-ff55-aa66-77bb77bb77bb)

Créer une colonne de recherche client

Contrairement à d’autres attributs, un attribut de recherche client est créé à l’aide de l’action CreateCustomerRelationships.

Les paramètres de cette action nécessitent la définition de l’attribut de recherche et une paire de relations un-à-plusieurs. Un attribut de recherche client a deux relations un-à-plusieurs : une à l’entité Compte et l’autre à l’entité Contact.

L’exemple suivant utilise ces propriétés pour créer un attribut de recherche client.

Propriétés de l’attribut de recherche client Valeurs
SchemaName new_CustomerId
DisplayName Client
Description Exemple d’attribut de recherche client

L’exemple crée un attribut de recherche client, new_CustomerIdet l’ajoute à l’entité personnalisée : new_bankaccount. La réponse est un CreateCustomerRelationshipsResponse ComplexType".

Requête :

POST [Organization URI]/api/data/v9.2/CreateCustomerRelationships HTTP/1.1
MSCRM.SolutionUniqueName: examplesolution
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"  
    }  
}  

Réponse:

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

Créer une colonne décimale

L’exemple suivant utilise ces propriétés pour créer une colonne décimale.

Propriétés de DecimalAttributeMetadata Valeurs
SchemaName sample_Decimal
DisplayName Exemple de nombre décimal
Description Attribut décimal
RequiredLevel None
MaxValue 100.0
MinValue 0,0
Precision 1

L’exemple suivant crée un attribut décimal à l’aide des propriétés et l’ajoute à la sample_bankaccount table.

L’URI de l’attribut est retourné dans la réponse.

Requête :

POST [Organization Uri]/api/data/v9.2/EntityDefinitions(LogicalName='sample_bankaccount')/Attributes
MSCRM.SolutionUniqueName: examplesolution
OData-MaxVersion: 4.0
OData-Version: 4.0
If-None-Match: null
Accept: application/json
Content-Type: application/json; charset=utf-8
Content-Length: 1370

{
  "@odata.type": "Microsoft.Dynamics.CRM.DecimalAttributeMetadata",
  "AttributeType": "Decimal",
  "AttributeTypeName": {
    "Value": "DecimalType"
  },
  "MaxValue": 100.0,
  "MinValue": 0.0,
  "Precision": 1,
  "Description": {
    "@odata.type": "Microsoft.Dynamics.CRM.Label",
    "LocalizedLabels": [
      {
        "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
        "Label": "Decimal Attribute",
        "LanguageCode": 1033,
        "IsManaged": false
      }
    ],
    "UserLocalizedLabel": {
      "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
      "Label": "Decimal Attribute",
      "LanguageCode": 1033,
      "IsManaged": false
    }
  },
  "DisplayName": {
    "@odata.type": "Microsoft.Dynamics.CRM.Label",
    "LocalizedLabels": [
      {
        "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
        "Label": "Sample Decimal",
        "LanguageCode": 1033,
        "IsManaged": false
      }
    ],
    "UserLocalizedLabel": {
      "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
      "Label": "Sample Decimal",
      "LanguageCode": 1033,
      "IsManaged": false
    }
  },
  "RequiredLevel": {
    "Value": "None",
    "CanBeChanged": false,
    "ManagedPropertyLogicalName": "canmodifyrequirementlevelsettings"
  },
  "SchemaName": "sample_Decimal"
}

Réponse:

HTTP/1.1 204 NoContent
OData-Version: 4.0
OData-EntityId: [Organization Uri]/api/data/v9.2/EntityDefinitions(LogicalName='sample_bankaccount')/Attributes(44ee44ee-ff55-aa66-bb77-88cc88cc88cc)

Créer une colonne entière

L’exemple suivant utilise ces propriétés pour créer une colonne entière.

Propriétés IntegerAttributeMetadata Valeurs
SchemaName sample_Integer
DisplayName Exemple d’entier
Description Attribut entier
RequiredLevel None
MaxValue 100
MinValue 0
Format Aucun

L’exemple suivant crée une colonne entière à l’aide des propriétés et l’ajoute à la sample_bankaccount table.

L’URI de la colonne est retournée dans la réponse.

Requête :

POST [Organization Uri]/api/data/v9.2/EntityDefinitions(LogicalName='sample_bankaccount')/Attributes
MSCRM.SolutionUniqueName: examplesolution
OData-MaxVersion: 4.0
OData-Version: 4.0
If-None-Match: null
Accept: application/json
Content-Type: application/json; charset=utf-8
Content-Length: 1392

{
  "@odata.type": "Microsoft.Dynamics.CRM.IntegerAttributeMetadata",
  "AttributeType": "Integer",
  "AttributeTypeName": {
    "Value": "IntegerType"
  },
  "MaxValue": 100,
  "MinValue": 0,
  "Format": "None",
  "SourceTypeMask": 0,
  "Description": {
    "@odata.type": "Microsoft.Dynamics.CRM.Label",
    "LocalizedLabels": [
      {
        "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
        "Label": "Integer Attribute",
        "LanguageCode": 1033,
        "IsManaged": false
      }
    ],
    "UserLocalizedLabel": {
      "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
      "Label": "Integer Attribute",
      "LanguageCode": 1033,
      "IsManaged": false
    }
  },
  "DisplayName": {
    "@odata.type": "Microsoft.Dynamics.CRM.Label",
    "LocalizedLabels": [
      {
        "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
        "Label": "Sample Integer",
        "LanguageCode": 1033,
        "IsManaged": false
      }
    ],
    "UserLocalizedLabel": {
      "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
      "Label": "Sample Integer",
      "LanguageCode": 1033,
      "IsManaged": false
    }
  },
  "RequiredLevel": {
    "Value": "None",
    "CanBeChanged": false,
    "ManagedPropertyLogicalName": "canmodifyrequirementlevelsettings"
  },
  "SchemaName": "sample_Integer"
}

Réponse:

HTTP/1.1 204 NoContent
OData-Version: 4.0
OData-EntityId: [Organization Uri]/api/data/v9.2/EntityDefinitions(LogicalName='sample_bankaccount')/Attributes(55ff55ff-aa66-bb77-cc88-99dd99dd99dd)

Créer une colonne mémo

L’exemple suivant utilise ces propriétés pour créer une colonne mémo.

Propriétés MemoAttributeMetadata Valeurs
SchemaName sample_Memo
DisplayName Exemple de mémo
Description Attribut Mémo
RequiredLevel None
MaxLength 500
Format TextArea

L’exemple suivant crée une colonne mémo à l’aide des propriétés et l’ajoute à la sample_bankaccount table.

L’URI de l’attribut est retourné dans la réponse.

Requête :

POST [Organization Uri]/api/data/v9.2/EntityDefinitions(LogicalName='sample_bankaccount')/Attributes
MSCRM.SolutionUniqueName: examplesolution
OData-MaxVersion: 4.0
OData-Version: 4.0
If-None-Match: null
Accept: application/json
Content-Type: application/json; charset=utf-8
Content-Length: 1384

{
  "@odata.type": "Microsoft.Dynamics.CRM.MemoAttributeMetadata",
  "AttributeType": "Memo",
  "AttributeTypeName": {
    "Value": "MemoType"
  },
  "Format": "TextArea",
  "ImeMode": "Disabled",
  "MaxLength": 500,
  "IsLocalizable": false,
  "Description": {
    "@odata.type": "Microsoft.Dynamics.CRM.Label",
    "LocalizedLabels": [
      {
        "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
        "Label": "Memo Attribute",
        "LanguageCode": 1033,
        "IsManaged": false
      }
    ],
    "UserLocalizedLabel": {
      "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
      "Label": "Memo Attribute",
      "LanguageCode": 1033,
      "IsManaged": false
    }
  },
  "DisplayName": {
    "@odata.type": "Microsoft.Dynamics.CRM.Label",
    "LocalizedLabels": [
      {
        "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
        "Label": "Sample Memo",
        "LanguageCode": 1033,
        "IsManaged": false
      }
    ],
    "UserLocalizedLabel": {
      "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
      "Label": "Sample Memo",
      "LanguageCode": 1033,
      "IsManaged": false
    }
  },
  "RequiredLevel": {
    "Value": "None",
    "CanBeChanged": false,
    "ManagedPropertyLogicalName": "canmodifyrequirementlevelsettings"
  },
  "SchemaName": "sample_Memo"
}

Réponse:

HTTP/1.1 204 NoContent
OData-Version: 4.0
OData-EntityId: [Organization Uri]/api/data/v9.2/EntityDefinitions(LogicalName='sample_bankaccount')/Attributes(66aa66aa-bb77-cc88-dd99-00ee00ee00ee)

Créer une colonne de choix

L’exemple suivant utilise ces propriétés pour créer une colonne de choix local.

Propriétés « PicklistAttributeMetadata » Valeurs
SchemaName sample_Choice
DisplayName Exemple de choix
Description Attribut de Choix
RequiredLevel None
OptionSet value :727000000, label :Bravo
value :, label :727000001Delta
value :727000002, label :Alpha
value :727000003, label :Charlie
value :, label :727000004Foxtrot

L’exemple suivant crée une colonne locale à l’aide des propriétés et l’ajoute à la sample_bankaccount table.

L’URI de l’attribut est retourné dans la réponse.

Note

Pour obtenir un exemple montrant comment créer une colonne de choix avec un ensemble d’options globales, consultez Créer une colonne de choix à l’aide d’un ensemble d’options globales

Requête :

POST [Organization Uri]/api/data/v9.2/EntityDefinitions(LogicalName='sample_bankaccount')/Attributes
MSCRM.SolutionUniqueName: examplesolution
OData-MaxVersion: 4.0
OData-Version: 4.0
If-None-Match: null
Accept: application/json
Content-Type: application/json; charset=utf-8
Content-Length: 4524

{
  "@odata.type": "Microsoft.Dynamics.CRM.PicklistAttributeMetadata",
  "AttributeType": "Picklist",
  "AttributeTypeName": {
    "Value": "PicklistType"
  },
  "SourceTypeMask": 0,
  "OptionSet": {
    "@odata.type": "Microsoft.Dynamics.CRM.OptionSetMetadata",
    "Options": [
      {
        "Value": 727000000,
        "Label": {
          "@odata.type": "Microsoft.Dynamics.CRM.Label",
          "LocalizedLabels": [
            {
              "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
              "Label": "Bravo",
              "LanguageCode": 1033,
              "IsManaged": false
            }
          ],
          "UserLocalizedLabel": {
            "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
            "Label": "Bravo",
            "LanguageCode": 1033,
            "IsManaged": false
          }
        }
      },
      {
        "Value": 727000001,
        "Label": {
          "@odata.type": "Microsoft.Dynamics.CRM.Label",
          "LocalizedLabels": [
            {
              "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
              "Label": "Delta",
              "LanguageCode": 1033,
              "IsManaged": false
            }
          ],
          "UserLocalizedLabel": {
            "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
            "Label": "Delta",
            "LanguageCode": 1033,
            "IsManaged": false
          }
        }
      },
      {
        "Value": 727000002,
        "Label": {
          "@odata.type": "Microsoft.Dynamics.CRM.Label",
          "LocalizedLabels": [
            {
              "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
              "Label": "Alpha",
              "LanguageCode": 1033,
              "IsManaged": false
            }
          ],
          "UserLocalizedLabel": {
            "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
            "Label": "Alpha",
            "LanguageCode": 1033,
            "IsManaged": false
          }
        }
      },
      {
        "Value": 727000003,
        "Label": {
          "@odata.type": "Microsoft.Dynamics.CRM.Label",
          "LocalizedLabels": [
            {
              "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
              "Label": "Charlie",
              "LanguageCode": 1033,
              "IsManaged": false
            }
          ],
          "UserLocalizedLabel": {
            "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
            "Label": "Charlie",
            "LanguageCode": 1033,
            "IsManaged": false
          }
        }
      },
      {
        "Value": 727000004,
        "Label": {
          "@odata.type": "Microsoft.Dynamics.CRM.Label",
          "LocalizedLabels": [
            {
              "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
              "Label": "Foxtrot",
              "LanguageCode": 1033,
              "IsManaged": false
            }
          ],
          "UserLocalizedLabel": {
            "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
            "Label": "Foxtrot",
            "LanguageCode": 1033,
            "IsManaged": false
          }
        }
      }
    ],
    "IsGlobal": false,
    "OptionSetType": "Picklist"
  },
  "Description": {
    "@odata.type": "Microsoft.Dynamics.CRM.Label",
    "LocalizedLabels": [
      {
        "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
        "Label": "Choice Attribute",
        "LanguageCode": 1033,
        "IsManaged": false
      }
    ],
    "UserLocalizedLabel": {
      "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
      "Label": "Choice Attribute",
      "LanguageCode": 1033,
      "IsManaged": false
    }
  },
  "DisplayName": {
    "@odata.type": "Microsoft.Dynamics.CRM.Label",
    "LocalizedLabels": [
      {
        "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
        "Label": "Sample Choice",
        "LanguageCode": 1033,
        "IsManaged": false
      }
    ],
    "UserLocalizedLabel": {
      "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
      "Label": "Sample Choice",
      "LanguageCode": 1033,
      "IsManaged": false
    }
  },
  "RequiredLevel": {
    "Value": "None",
    "CanBeChanged": false,
    "ManagedPropertyLogicalName": "canmodifyrequirementlevelsettings"
  },
  "SchemaName": "sample_Choice"
}

Réponse:

HTTP/1.1 204 NoContent
OData-Version: 4.0
OData-EntityId: [Organization Uri]/api/data/v9.2/EntityDefinitions(LogicalName='sample_bankaccount')/Attributes(00aa00aa-bb11-cc22-dd33-44ee44ee44ee)

Créer une colonne à choix multiples

L’exemple suivant utilise ces propriétés pour créer une colonne de choix multi-sélection locale.

Propriétés de l'attribut de liste de sélection multiple (MultiSelectPicklistAttributeMetadata) Valeurs
SchemaName sample_Choice
DisplayName Exemple de choix
Description Attribut de choix
RequiredLevel None
OptionSet value :, label :727000000Appetizer
value :, label :727000001Entree
value :727000002, label :Dessert

L’exemple suivant crée une colonne de choix à sélection multiple locale à l’aide des propriétés et l’ajoute à la sample_bankaccount table.

L’URI de l’attribut est retourné dans la réponse.

Requête :

POST [Organization Uri]/api/data/v9.2/EntityDefinitions(LogicalName='sample_bankaccount')/Attributes
MSCRM.SolutionUniqueName: examplesolution
OData-MaxVersion: 4.0
OData-Version: 4.0
If-None-Match: null
Accept: application/json
Content-Type: application/json; charset=utf-8
Content-Length: 3404

{
  "@odata.type": "Microsoft.Dynamics.CRM.MultiSelectPicklistAttributeMetadata",
  "AttributeType": "Virtual",
  "AttributeTypeName": {
    "Value": "MultiSelectPicklistType"
  },
  "SourceTypeMask": 0,
  "OptionSet": {
    "@odata.type": "Microsoft.Dynamics.CRM.OptionSetMetadata",
    "Options": [
      {
        "Value": 727000000,
        "Label": {
          "@odata.type": "Microsoft.Dynamics.CRM.Label",
          "LocalizedLabels": [
            {
              "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
              "Label": "Appetizer",
              "LanguageCode": 1033,
              "IsManaged": false
            }
          ],
          "UserLocalizedLabel": {
            "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
            "Label": "Appetizer",
            "LanguageCode": 1033,
            "IsManaged": false
          }
        }
      },
      {
        "Value": 727000001,
        "Label": {
          "@odata.type": "Microsoft.Dynamics.CRM.Label",
          "LocalizedLabels": [
            {
              "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
              "Label": "Entree",
              "LanguageCode": 1033,
              "IsManaged": false
            }
          ],
          "UserLocalizedLabel": {
            "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
            "Label": "Entree",
            "LanguageCode": 1033,
            "IsManaged": false
          }
        }
      },
      {
        "Value": 727000002,
        "Label": {
          "@odata.type": "Microsoft.Dynamics.CRM.Label",
          "LocalizedLabels": [
            {
              "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
              "Label": "Dessert",
              "LanguageCode": 1033,
              "IsManaged": false
            }
          ],
          "UserLocalizedLabel": {
            "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
            "Label": "Dessert",
            "LanguageCode": 1033,
            "IsManaged": false
          }
        }
      }
    ],
    "IsGlobal": false,
    "OptionSetType": "Picklist"
  },
  "Description": {
    "@odata.type": "Microsoft.Dynamics.CRM.Label",
    "LocalizedLabels": [
      {
        "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
        "Label": "MultiSelect Choice Attribute",
        "LanguageCode": 1033,
        "IsManaged": false
      }
    ],
    "UserLocalizedLabel": {
      "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
      "Label": "MultiSelect Choice Attribute",
      "LanguageCode": 1033,
      "IsManaged": false
    }
  },
  "DisplayName": {
    "@odata.type": "Microsoft.Dynamics.CRM.Label",
    "LocalizedLabels": [
      {
        "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
        "Label": "Sample MultiSelect Choice",
        "LanguageCode": 1033,
        "IsManaged": false
      }
    ],
    "UserLocalizedLabel": {
      "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
      "Label": "Sample MultiSelect Choice",
      "LanguageCode": 1033,
      "IsManaged": false
    }
  },
  "RequiredLevel": {
    "Value": "None",
    "CanBeChanged": false,
    "ManagedPropertyLogicalName": "canmodifyrequirementlevelsettings"
  },
  "SchemaName": "sample_MultiSelectChoice"
}

Réponse:

HTTP/1.1 204 NoContent
OData-Version: 4.0
OData-EntityId: [Organization Uri]/api/data/v9.2/EntityDefinitions(LogicalName='sample_bankaccount')/Attributes(11bb11bb-cc22-dd33-ee44-55ff55ff55ff)

Créer une colonne de type entier longue

L’exemple suivant utilise ces propriétés pour créer une colonne entière volumineuse.

Propriétés de BigIntAttributeMetadata Valeurs
SchemaName sample_BigInt
DisplayName Exemple de BigInt
Description Attribut BigInt
RequiredLevel None

L’exemple suivant crée une colonne entière à l’aide des propriétés et l’ajoute à la sample_bankaccount table.

L’URI de la colonne est retourné dans la réponse.

Requête

POST [Organization Uri]/api/data/v9.2/EntityDefinitions(LogicalName='sample_bankaccount')/Attributes
MSCRM.SolutionUniqueName: examplesolution
OData-MaxVersion: 4.0
OData-Version: 4.0
If-None-Match: null
Accept: application/json
Authorization: Bearer <access token>
Content-Type: application/json; charset=utf-8
Content-Length: 1301

{
  "AttributeType": "BigInt",
  "AttributeTypeName": {
    "Value": "BigIntType"
  },
  "@odata.type": "Microsoft.Dynamics.CRM.BigIntAttributeMetadata",
  "Description": {
    "@odata.type": "Microsoft.Dynamics.CRM.Label",
    "LocalizedLabels": [
      {
        "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
        "Label": "BigInt Attribute",
        "LanguageCode": 1033,
        "IsManaged": false
      }
    ],
    "UserLocalizedLabel": {
      "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
      "Label": "BigInt Attribute",
      "LanguageCode": 1033,
      "IsManaged": false
    }
  },
  "DisplayName": {
    "@odata.type": "Microsoft.Dynamics.CRM.Label",
    "LocalizedLabels": [
      {
        "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
        "Label": "Sample BigInt",
        "LanguageCode": 1033,
        "IsManaged": false
      }
    ],
    "UserLocalizedLabel": {
      "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
      "Label": "Sample BigInt",
      "LanguageCode": 1033,
      "IsManaged": false
    }
  },
  "RequiredLevel": {
    "Value": "None",
    "CanBeChanged": false,
    "ManagedPropertyLogicalName": "canmodifyrequirementlevelsettings"
  },
  "SchemaName": "sample_BigInt"
}

Réponse

HTTP/1.1 204 NoContent
OData-Version: 4.0
OData-EntityId: [Organization Uri]/api/data/v9.2/EntityDefinitions(LogicalName='sample_bankaccount')/Attributes(22cc22cc-dd33-ee44-ff55-66aa66aa66aa)

Mettre à jour une colonne

Comme mentionné dans les définitions de table Update, les entités de modèle de données sont mises à jour à l’aide de la méthode HTTP PUT avec la définition JSON entière de l’élément actuel. Ce modèle s’applique aux attributs d’entité et aux entités. Comme avec les entités, vous pouvez remplacer les étiquettes à l’aide de l’en-tête MSCRM.MergeLabels avec la valeur définie sur false, et vous devez publier les personnalisations avant qu'elles ne soient actives dans le système.

À l’aide de l’attribut booléen créé dans Créer une colonne booléenne ci-dessus, nous devons d’abord récupérer l’attribut entier.

Requête :

GET [Organization Uri]/api/data/v9.2/EntityDefinitions(LogicalName='new_bankaccount')/Attributes(LogicalName='new_boolean')/Microsoft.Dynamics.CRM.BooleanAttributeMetadata HTTP/1.1
OData-MaxVersion: 4.0
OData-Version: 4.0
If-None-Match: null
Accept: application/json

Réponse:

HTTP/1.1 OK
OData-Version: 4.0

{
  "@odata.context": "[Organization Uri]/api/data/v9.2/$metadata#EntityDefinitions('new_bankaccount')/Attributes/Microsoft.Dynamics.CRM.BooleanAttributeMetadata/$entity",
  "MetadataId": "33dd33dd-ee44-ff55-aa66-77bb77bb77bb",
  "HasChanged": null,
  "AttributeOf": null,
  "AttributeType": "Boolean",
  "ColumnNumber": 35,
  "DeprecatedVersion": null,
  "IntroducedVersion": "1.0.0.0",
  "EntityLogicalName": "new_bankaccount",
  "IsCustomAttribute": true,
  "IsPrimaryId": false,
  "IsValidODataAttribute": true,
  "IsPrimaryName": false,
  "IsValidForCreate": true,
  "IsValidForRead": true,
  "IsValidForUpdate": true,
  "CanBeSecuredForRead": true,
  "CanBeSecuredForCreate": true,
  "CanBeSecuredForUpdate": true,
  "IsSecured": false,
  "IsRetrievable": false,
  "IsFilterable": false,
  "IsSearchable": false,
  "IsManaged": false,
  "LinkedAttributeId": null,
  "LogicalName": "new_boolean",
  "IsValidForForm": true,
  "IsRequiredForForm": false,
  "IsValidForGrid": true,
  "SchemaName": "new_Boolean",
  "ExternalName": null,
  "IsLogical": false,
  "IsDataSourceSecret": false,
  "InheritsFrom": null,
  "CreatedOn": "2022-08-08T22:19:49Z",
  "ModifiedOn": "2022-08-08T22:19:49Z",
  "SourceType": 0,
  "AutoNumberFormat": null,
  "DefaultValue": false,
  "FormulaDefinition": "",
  "SourceTypeMask": 0,
  "AttributeTypeName": {
    "Value": "BooleanType"
  },
  "Description": {
    "LocalizedLabels": [
      {
        "Label": "Boolean Attribute",
        "LanguageCode": 1033,
        "IsManaged": false,
        "MetadataId": "2b5545d2-a59b-4503-8846-95665283b41f",
        "HasChanged": null
      }
    ],
    "UserLocalizedLabel": {
      "Label": "Boolean Attribute",
      "LanguageCode": 1033,
      "IsManaged": false,
      "MetadataId": "2b5545d2-a59b-4503-8846-95665283b41f",
      "HasChanged": null
    }
  },
  "DisplayName": {
    "LocalizedLabels": [
      {
        "Label": "Sample Boolean",
        "LanguageCode": 1033,
        "IsManaged": false,
        "MetadataId": "e6b8d06c-067e-4ab0-a9a8-32f520b25e36",
        "HasChanged": null
      }
    ],
    "UserLocalizedLabel": {
      "Label": "Sample Boolean",
      "LanguageCode": 1033,
      "IsManaged": false,
      "MetadataId": "e6b8d06c-067e-4ab0-a9a8-32f520b25e36",
      "HasChanged": null
    }
  },
  "IsAuditEnabled": {
    "Value": true,
    "CanBeChanged": true,
    "ManagedPropertyLogicalName": "canmodifyauditsettings"
  },
  "IsGlobalFilterEnabled": {
    "Value": false,
    "CanBeChanged": true,
    "ManagedPropertyLogicalName": "canmodifyglobalfiltersettings"
  },
  "IsSortableEnabled": {
    "Value": false,
    "CanBeChanged": true,
    "ManagedPropertyLogicalName": "canmodifyissortablesettings"
  },
  "IsCustomizable": {
    "Value": true,
    "CanBeChanged": true,
    "ManagedPropertyLogicalName": "iscustomizable"
  },
  "IsRenameable": {
    "Value": true,
    "CanBeChanged": true,
    "ManagedPropertyLogicalName": "isrenameable"
  },
  "IsValidForAdvancedFind": {
    "Value": true,
    "CanBeChanged": true,
    "ManagedPropertyLogicalName": "canmodifysearchsettings"
  },
  "RequiredLevel": {
    "Value": "None",
    "CanBeChanged": false,
    "ManagedPropertyLogicalName": "canmodifyrequirementlevelsettings"
  },
  "CanModifyAdditionalSettings": {
    "Value": true,
    "CanBeChanged": true,
    "ManagedPropertyLogicalName": "canmodifyadditionalsettings"
  },
  "Settings": []
}

Ensuite, modifiez les propriétés que vous souhaitez modifier.

Les propriétés BooleanAttributeMetadata Anciennes valeurs Nouvelles valeurs
DisplayName Exemple booléen Exemple booléen mis à jour
Description Attribut booléen Attribut booléen mis à jour
RequiredLevel None ApplicationRequired

Note

Si vous souhaitez mettre à jour les options, vous devez envoyer une autre demande. Plus d’informations : Options de mise à jour.

Vous pouvez maintenant envoyer la PUT requête avec les propriétés modifiées :

Requête :

PUT [Organization Uri]/api/data/v9.2/EntityDefinitions(LogicalName='new_bankaccount')/Attributes(LogicalName='new_boolean') HTTP/1.1
MSCRM.SolutionUniqueName: examplesolution
MSCRM.MergeLabels: true
OData-MaxVersion: 4.0
OData-Version: 4.0
If-None-Match: null
Accept: application/json

{
  "@odata.type": "Microsoft.Dynamics.CRM.BooleanAttributeMetadata",
  "MetadataId": "e160ff9b-6f17-ed11-b83e-00224837179f",
  "HasChanged": null,
  "AttributeOf": null,
  "AttributeType": "Boolean",
  "ColumnNumber": 35,
  "DeprecatedVersion": null,
  "IntroducedVersion": "1.0.0.0",
  "EntityLogicalName": "new_bankaccount",
  "IsCustomAttribute": true,
  "IsPrimaryId": false,
  "IsValidODataAttribute": true,
  "IsPrimaryName": false,
  "IsValidForCreate": true,
  "IsValidForRead": true,
  "IsValidForUpdate": true,
  "CanBeSecuredForRead": true,
  "CanBeSecuredForCreate": true,
  "CanBeSecuredForUpdate": true,
  "IsSecured": false,
  "IsRetrievable": false,
  "IsFilterable": false,
  "IsSearchable": false,
  "IsManaged": false,
  "LinkedAttributeId": null,
  "LogicalName": "new_boolean",
  "IsValidForForm": true,
  "IsRequiredForForm": false,
  "IsValidForGrid": true,
  "SchemaName": "new_Boolean",
  "ExternalName": null,
  "IsLogical": false,
  "IsDataSourceSecret": false,
  "InheritsFrom": null,
  "CreatedOn": "2022-08-08T23:12:55Z",
  "ModifiedOn": "2022-08-08T23:12:55Z",
  "SourceType": 0,
  "AutoNumberFormat": null,
  "DefaultValue": false,
  "FormulaDefinition": "",
  "SourceTypeMask": 0,
  "AttributeTypeName": {
    "Value": "BooleanType"
  },
  "Description": {
    "LocalizedLabels": [
      {
        "Label": "Boolean Attribute Updated",
        "LanguageCode": 1033,
        "IsManaged": false,
        "MetadataId": "b370f0dd-329f-434e-8b9f-b6eb47d0141f",
        "HasChanged": null
      }
    ],
    "UserLocalizedLabel": {
      "Label": "Boolean Attribute Updated",
      "LanguageCode": 1033,
      "IsManaged": false,
      "MetadataId": "b370f0dd-329f-434e-8b9f-b6eb47d0141f",
      "HasChanged": null
    }
  },
  "DisplayName": {
    "LocalizedLabels": [
      {
        "Label": "Sample Boolean Updated",
        "LanguageCode": 1033,
        "IsManaged": false,
        "MetadataId": "63a9e5f1-e730-40cb-a410-495367d5856d",
        "HasChanged": null
      }
    ],
    "UserLocalizedLabel": {
      "Label": "Sample Boolean Updated",
      "LanguageCode": 1033,
      "IsManaged": false,
      "MetadataId": "63a9e5f1-e730-40cb-a410-495367d5856d",
      "HasChanged": null
    }
  },
  "IsAuditEnabled": {
    "Value": true,
    "CanBeChanged": true,
    "ManagedPropertyLogicalName": "canmodifyauditsettings"
  },
  "IsGlobalFilterEnabled": {
    "Value": false,
    "CanBeChanged": true,
    "ManagedPropertyLogicalName": "canmodifyglobalfiltersettings"
  },
  "IsSortableEnabled": {
    "Value": false,
    "CanBeChanged": true,
    "ManagedPropertyLogicalName": "canmodifyissortablesettings"
  },
  "IsCustomizable": {
    "Value": true,
    "CanBeChanged": true,
    "ManagedPropertyLogicalName": "iscustomizable"
  },
  "IsRenameable": {
    "Value": true,
    "CanBeChanged": true,
    "ManagedPropertyLogicalName": "isrenameable"
  },
  "IsValidForAdvancedFind": {
    "Value": true,
    "CanBeChanged": true,
    "ManagedPropertyLogicalName": "canmodifysearchsettings"
  },
  "RequiredLevel": {
    "Value": "ApplicationRequired",
    "CanBeChanged": false,
    "ManagedPropertyLogicalName": "canmodifyrequirementlevelsettings"
  },
  "CanModifyAdditionalSettings": {
    "Value": true,
    "CanBeChanged": true,
    "ManagedPropertyLogicalName": "canmodifyadditionalsettings"
  },
  "Settings": []
}

Réponse:

HTTP/1.1 NoContent
OData-Version: 4.0
OData-EntityId: [Organization Uri]/api/data/v9.2/EntityDefinitions(LogicalName='new_bankaccount')/Attributes(LogicalName='new_boolean')

Voir aussi

Utiliser l’API web avec les métadonnées Microsoft Dataverse
Créer et mettre à jour les définitions de table à l’aide de l’API Web
Requête des définitions de table à l’aide de l’API web
Récupérer les définitions de table par nom ou MetadataId
Relations de table de modèles à l’aide de l’API web
Utiliser des définitions de table à l’aide du Kit de développement logiciel (SDK) pour .NET
Définitions de colonne (attribut)
Exemple d’opérations de schéma de table de l’API Web
Exemple d’opérations de schéma de table de l’API Web (C#)