Share via


Crear y actualizar definiciones de columna mediante la API web

Puede realizar las mismas operaciones en las definiciones de columna utilizando la API web que con el SDK para .NET. Este artículo se centra en el trabajo con definiciones de columnas de tablas (metadatos) utilizando la API web.

Crear columnas

Puede crear columnas de tabla (atributos de entidad) al mismo tiempo que crea la definición de tabla al incluir la definición JSON de los atributos en la matriz Attributes para la entidad que publica además del atributo de cadena que sirve como atributo de nombre principal. Si desea agregar atributos a una entidad que ya está creada, puede enviar una solicitud POST incluyendo su definición JSON a la propiedad de navegación valorada como colección Attributes de la entidad.

Este ejemplo muestra cómo crear diferentes tipos de columnas

Crear una columna string

El siguiente ejemplo usará estas propiedades para crear una columna de cadena.

Propiedades de StringAttributeMetadata Valores
SchemaName new_BankName
DisplayName Nombre del banco
Description Escriba el nombre del banco.
RequiredLevel None
MaxLength 100
FormatName Text

El siguiente ejemplo crea una columna de cadena usando las propiedades y la agrega a la tabla sample_bankaccount.

El URI para el atributo se devuelve en la respuesta.

Solicitud:

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  
}  
  

Respuesta:

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)  

Crear una columna dinero

El siguiente ejemplo usará estas propiedades para crear un atributo monetario.

Propiedades de MoneyAttributeMetadata Valores
SchemaName new_Balance
DisplayName Saldo
Description Especifique el importe de saldo.
RequiredLevel None
PrecisionSource 2
Nota: para obtener información sobre los valores válidos para PrecisionSource, vea MoneyType. El valor 2 indica que el nivel de precisión decimal coincidirá con TransactionCurrency.CurrencyPrecision, que está asociada con el registro actual.

El siguiente ejemplo crea un atributo monetario usando las propiedades y la agrega a la tabla sample_bankaccount. El URI para el atributo se devuelve en la respuesta.

Solicitud:

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  
}  

Respuesta:

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)  

Crear una columna datetime

El siguiente ejemplo usará estas propiedades para crear un atributo de fecha y hora.

Propiedades de DateTimeAttributeMetadata Valores
SchemaName new_Checkeddate
DisplayName Date
Description Fecha en que se confirmó por última vez el saldo de cuenta.
RequiredLevel None
Format DateOnly Nota: para las opciones válidas para esta propiedad, consulte DateTimeFormat EnumType

El siguiente ejemplo crea un atributo datetime usando las propiedades y la agrega a la tabla sample_bankaccount. El URI para el atributo se devuelve en la respuesta.

Solicitud:

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

Respuesta:

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)  

Crear una columna booleana

El siguiente ejemplo usará estas propiedades para crear una columna booleana.

Propiedades de BooleanAttributeMetadata Valores
SchemaName new_Boolean
DisplayName Booleano de muestra
Description Atributo booleano
RequiredLevel None
OptionSet.TrueOption VERDADERO
OptionSet.FalseOption False

El siguiente ejemplo crea un atributo booleano mediante las propiedades y lo agrega a la entidad con el valor LogicalName de new_bankaccount. El URI para el atributo se devuelve en la respuesta.

Solicitud:

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

Respuesta:

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)

Crear una columna de búsqueda de clientes

A diferencia de otros atributos, un atributo de búsqueda de cliente se crea mediante la acción CreateCustomerRelationships.

Los parámetros de esta acción requieren la definición del atributo de búsqueda y un par de relaciones de uno a varios. Un atributo de búsqueda de cliente tiene dos relaciones de uno a varios: una para la entidad de cuenta y la otra para la entidad de contacto.

El siguiente ejemplo usará estas propiedades para crear un atributo de búsqueda de clientes.

Propiedades del atributo de búsqueda de clientes Valores
SchemaName new_CustomerId
DisplayName Customer
Description Atributo de búsqueda de clientes de ejemplo

El ejemplo crea un atributo de búsqueda de clientes new_CustomerId, y lo agrega a la entidad personalizada: new_bankaccount. La respuesta es un CreateCustomerRelationshipsResponse ComplexType".

Solicitud:

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

Respuesta:

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

Crear una columna decimal

El siguiente ejemplo usará estas propiedades para crear una columna decimal.

Propiedades de DecimalAttributeMetadata Valores
SchemaName sample_Decimal
DisplayName Muestra decimal
Description Atributo decimal
RequiredLevel None
MaxValue 100.0
MinValue 0.0
Precision 1

El siguiente ejemplo crea un atributo decimal usando las propiedades y la agrega a la tabla sample_bankaccount.

El URI para el atributo se devuelve en la respuesta.

Solicitud:

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

Respuesta:

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)

Crear una columna de numero entero

El siguiente ejemplo usará estas propiedades para crear una columna de números enteros.

Propiedades de IntegerAttributeMetadata Valores
SchemaName sample_Integer
DisplayName Entero de muestra
Description Atributo entero
RequiredLevel None
MaxValue 100
MinValue 0
Format None

El siguiente ejemplo crea una columna de números enteros usando las propiedades y la agrega a la tabla sample_bankaccount.

El URI para la columna se devuelve en la respuesta.

Solicitud:

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

Respuesta:

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)

Crear una columna de memorándum

El siguiente ejemplo usará estas propiedades para crear una columna de memorándum.

Propiedades de MemoAttributeMetadata Valores
SchemaName sample_Memo
DisplayName Memorándum de muestra
Description Atributo de memorando
RequiredLevel None
MaxLength 500
Format TextArea

El siguiente ejemplo crea una columna de memorando usando las propiedades y la agrega a la tabla sample_bankaccount.

El URI para el atributo se devuelve en la respuesta.

Solicitud:

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

Respuesta:

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)

Crear una columna de elección

El siguiente ejemplo usará estas propiedades para crear una columna de elección local.

Propiedades de PicklistAttributeMetadata Valores
SchemaName sample_Choice
DisplayName Elección de muestra
Description Elegir un atributo
RequiredLevel None
OptionSet valor: 727000000, etiqueta: Bravo
valor: 727000001, etiqueta: Delta
valor: 727000002, etiqueta: Alpha
valor: 727000003, etiqueta: Charlie
valor: 727000004, etiqueta: Foxtrot

El siguiente ejemplo crea una columna local usando las propiedades y la agrega a la tabla sample_bankaccount.

El URI para el atributo se devuelve en la respuesta.

Nota

Para ver un ejemplo que muestra cómo crear una columna de opciones con un conjunto de opciones global, consulte Crear una columna de opciones usando un conjunto de opciones global

Solicitud:

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

Respuesta:

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)

Crear una columna de opciones de selección múltiple

El siguiente ejemplo usará estas propiedades para crear una columna de elección local de selección múltiple.

Propiedades de MultiSelectPicklistAttributeMetadata Valores
SchemaName sample_Choice
DisplayName Elección de muestra
Description Elegir un atributo
RequiredLevel None
OptionSet valor: 727000000, etiqueta: Entrante
valor:727000001, etiqueta:Entree
valor:727000002, etiqueta:Postre

El siguiente ejemplo crea una columna local de elección múltiple usando las propiedades y la agrega a la tabla sample_bankaccount.

El URI para el atributo se devuelve en la respuesta.

Solicitud:

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

Respuesta:

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)

Crear una columna de numero entero grande

El siguiente ejemplo usará estas propiedades para crear una columna de números enteros grandes.

Propiedades BigIntAttributeMetadata Valores
SchemaName sample_BigInt
DisplayName Muestra bigint
Description Atributo de bigint
RequiredLevel None

El siguiente ejemplo crea una columna de números enteros usando las propiedades y la agrega a la tabla sample_bankaccount.

El URI para la columna se devuelve en la respuesta.

Solicitar

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)

Actualizar una columna

Como se menciona en Actualizar definiciones de tablas, las entidades del modelo de datos se actualizan mediante el método HTTP PUT con la definición JSON completa del elemento actual. Este patrón se aplica tanto a los atributos de entidad como a las entidades. Al igual con las entidades, puede la opción de sobrescribir etiquetas mediante el encabezado MSCRM.MergeLabels con el valor establecido en false, y debe publicar personalizaciones antes de que estén activas en el sistema.

Usando el atributo booleano creado anteriormente en Crear una columna booleana, debemos, en primer lugar, recuperar el atributo completo.

Solicitud:

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

Respuesta:

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": []
}

Después, cambie las propiedades que desee cambiar.

Propiedades de BooleanAttributeMetadata Valores antiguos Valores nuevos
DisplayName Booleano de muestra Booleano de muestra actualizado
Description Atributo booleano Atributo booleano actualizado
RequiredLevel None ApplicationRequired

Nota

Si desea actualizar las opciones, debe enviar una solicitud diferente. Más información: Actualizar opciones.

Ahora puede enviar la solicitud PUT con las propiedades modificadas:

Solicitud:

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": []
}

Respuesta:

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

Consulte también

Usar la API web con metadatos de Microsoft Dataverse
Crear y actualizar definiciones de tabla mediante la API web
Consultar definiciones de tabla con la API web
Recuperar definiciones de tablas por nombre o MetadataId
Relaciones de tabla de modelos usando la API web
Trabajar con definiciones de tablas mediante SDK para .NET
Definiciones de columna (atributo)
Ejemplo de operaciones de esquema de tabla de API web
Ejemplo de operaciones de esquema de tabla de API web (C#)

Nota

¿Puede indicarnos sus preferencias de idioma de documentación? Realice una breve encuesta. (tenga en cuenta que esta encuesta está en inglés)

La encuesta durará unos siete minutos. No se recopilan datos personales (declaración de privacidad).