Créer et mettre à jour des définitions de colonne à l’aide de l’API Web

Vous pouvez exécuter les opérations sur les définitions de colonne en utilisant l’API web de la même manière qu’avec le SDK pour .NET. Cet article aborde l’utilisation des définitions de colonne (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 la table Attributes pour l’entité que vous publiez en plus de l’attribut de chaîne qui sert d’attribut de nom principal. Pour ajouter des attributs à une entité déjà créée, vous pouvez envoyer une demande POST incluant leur définition JSON à la propriété de navigation avec une valeur de collection Attributes de l’entité.

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 de 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 table sample_bankaccount.

L’URI pour l’attribut est renvoyée dans la réponse.

Demande :

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(f01bef16-287c-e511-80d2-00155d2a68d2)  

Créer une colonne monétaire

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 None
PrecisionSource 2
Remarque : pour plus d’informations sur les valeurs valides pour PrecisionSource, voir MoneyType. La valeur 2 indique que le niveau de précision décimale correspond à TransactionCurrency.CurrencyPrecision qui est associé à l’enregistrement actif.

L’exemple suivant crée un attribut monétaire à l’aide des propriétés et l’ajoute à la table sample_bankaccount. L’URI pour l’attribut est renvoyée dans la réponse.

Demande :

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(f11bef16-287c-e511-80d2-00155d2a68d2)  

Créer une colonne de date et heure

L’exemple suivant utilise ces propriétés pour créer un attribut de date et heure.

Propriétés de DateTimeAttributeMetadata Valeurs
SchemaName new_Checkeddate
DisplayName Date
Description La date où le solde de compte a été confirmé pour la dernière fois.
RequiredLevel None
Format DateOnly Remarque : pour les options valides de cette propriété, voir DateTimeFormat EnumType

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

Demande :

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(fe1bef16-287c-e511-80d2-00155d2a68d2)  

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 False

L’exemple suivant crée un attribut booléen en utilisant les propriétés et l’ajoute à l’entité ayant la valeur LogicalName de new_bankaccount. L’URI pour l’attribut est renvoyée dans la réponse.

Demande :

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(38d20735-6817-ed11-b83e-00224837179f)

Créer une colonne de recherche de client

À la différence d’autres attributs, un attribut de recherche de client est créé à l’aide de l’action CreateCustomerRelationships.

Les paramètres associés à 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 de client.

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

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

Demande :

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 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 table sample_bankaccount.

L’URI pour l’attribut est renvoyée dans la réponse.

Demande :

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(dba9c0df-4c05-ee11-8f6e-000d3a993550)

Créer une colonne d’entier

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

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

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

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

Demande :

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(17aac0df-4c05-ee11-8f6e-000d3a993550)

Créer une colonne de mémo

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

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

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

L’URI pour l’attribut est renvoyée dans la réponse.

Demande :

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(b12d3cee-4c05-ee11-8f6e-000d3a993550)

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 de PicklistAttributeMetadata Valeurs
SchemaName sample_Choice
DisplayName Exemple de choix
Description Attribut de choix
RequiredLevel None
OptionSet valeur :727000000, étiquette :Bravo
valeur :727000001, étiquette :Delta
valeur :727000002, étiquette :Alpha
valeur :727000003, étiquette :Charlie
valeur :727000004, étiquette :Foxtrot

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

L’URI pour l’attribut est renvoyée dans la réponse.

Notes

Pour voir un exemple montrant comment créer une colonne de choix avec un groupe d’options global, consultez Créer une colonne de choix à l’aide d’un groupe d’options global

Demande :

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(eed205fb-4c05-ee11-8f6e-000d3a993550)

Créer une colonne à choix multiple

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

Propriétés de MultiSelectPicklistAttributeMetadata Valeurs
SchemaName sample_Choice
DisplayName Exemple de choix
Description Attribut de choix
RequiredLevel None
OptionSet valeur :727000000, étiquette :Apéritif
valeur :727000001, étiquette :Entrée
valeur :727000002, étiquette :Dessert

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

L’URI pour l’attribut est renvoyée dans la réponse.

Demande :

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(afd63201-4d05-ee11-8f6e-000d3a993550)

Créer une grande colonne d’entier

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

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 d’entier à l’aide des propriétés et l’ajoute à la table sample_bankaccount.

L’URI de la colonne est renvoyé 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"
}

Response

HTTP/1.1 204 NoContent
OData-Version: 4.0
OData-EntityId: [Organization Uri]/api/data/v9.2/EntityDefinitions(LogicalName='sample_bankaccount')/Attributes(28b90018-1d99-ee11-be37-000d3a993223)

Mettre à jour une colonne

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

En utilisant l’attribut booléen créé dans Créer une colonne booléenne ci-dessus, il faut d’abord récupérer l’intégralité de l’attribut.

Demande :

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": "38d20735-6817-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-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, sélectionnez les propriétés à changer.

Propriétés de 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

Notes

Si vous souhaitez mettre à jour les options, vous devez envoyer une demande différente. Pour plus d’informations : Mettre à jour les options.

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

Demande :

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èle à l’aide de l’API Web
Utiliser les définitions de table à l’aide du SDK pour .NET
Définition 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#)

Notes

Pouvez-vous nous indiquer vos préférences de langue pour la documentation ? Répondez à un court questionnaire. (veuillez noter que ce questionnaire est en anglais)

Le questionnaire vous prendra environ sept minutes. Aucune donnée personnelle n’est collectée (déclaration de confidentialité).