Recherches multi-tables

Les colonnes de type de recherche multi-tables permettent d’utiliser une table spécifique qui a plusieurs relations un-à-plusieurs (1:N) avec d’autres tables de l’environnement. Une colonne de type de recherche unique peut faire référence à plusieurs autres tables. Une valeur de recherche soumise à la colonne de type multi-tables est mise en correspondance avec un enregistrement dans l’une des tables associées. Des recherches dans plusieurs tables peuvent être créées à la fois avec des tables locales et des tables virtuelles comme tables référencées.

Les types multi-tables sont actuellement intégrés à Microsoft Dataverse en tant que types statiques comme Client, qui se connecte à Compte et Contact. Cette nouvelle fonctionnalité permet aux utilisateurs de définir toutes les autres recherches multi-tables dont ils peuvent avoir besoin.

Notes

À l’heure actuelle, les utilisateurs peuvent créer et modifier des recherches multi-tables personnalisées par le SDK ou les API web. La prise en charge de l’interface utilisateur interactive sera disponible dans une prochaine version.

Examples

Supposons que vous hébergiez des médias pour les utilisateurs d’une bibliothèque. Vous avez différents MediaObjects dont beaucoup portent le même nom mais avec des formats différents comme « Books », « Audio » et « Vidéo ». En créant une recherche multi-tables appelée new_Media avec des relations 1 à N vers new_Books, new_Audio et new_Video, vous obtenez une table de recherche new_Media qui fournit l’identification rapide des enregistrements stockés dans certaines tables.

Table de recherche new_Media

PrimaryID PrimaryName RelatedID Nom associé
<media1> MediaObjectOne <books1> Content1
<media2> MediaObjectTwo <audio1> Content1
<media3> MediaObjectThree <video1> Content3
<media4> MediaObjectFour <audio2> Content3

Table new_Book

PrimaryID PrimaryName CallNumber
<books1> Content1 1ww-3452
<books2> Content2 a4e-87hw

Table new_Audio

PrimaryID PrimaryName AudioFormat
<audio1> Content1 mp4
<audio2> Content3 wma

Table new_Vidéo

PrimaryID PrimaryName VidéoFormat
<video1> Content3 wmv
<video2> Content2 avi

La recherche de média peut renvoyer des enregistrements dans toutes les tables de la recherche polymorphe.

  • Une recherche sur Média avec le nom Content1 récupèrerait les enregistrements pour <books1> et <audio1>

  • Une recherche sur Média avec Content3 récupèrerait les enregistrements pour <audio2> et <video1>

Exemple d’API web

La requête HTTP POST suivante crée un attribut de recherche polymorphe.

Requête

POST [Organization URI]/api/data/v9.2/CreatePolymorphicLookupAttribute HTTP/1.1 

Accept: application/json 
Content-Type: application/json; charset=utf-8 
OData-MaxVersion: 4.0 
OData-Version: 4.0 

{
 "OneToManyRelationships": [
   {
     "SchemaName": "new_media_new_book",
     "ReferencedEntity": "new_book",
     "ReferencingEntity": "new_media"
   },
   {
     "SchemaName": "new_media_new_video",
     "ReferencedEntity": "new_video",
     "ReferencingEntity": "new_media"
   },
   {
     "SchemaName": "new_media_new_audio",
     "ReferencedEntity": "new_audio",
     "ReferencingEntity": "new_media",
     "CascadeConfiguration": {  
        "Assign": "NoCascade",  
        "Delete": "RemoveLink",  
        "Merge": "NoCascade",  
        "Reparent": "NoCascade",  
        "Share": "NoCascade",  
        "Unshare": "NoCascade"  
     }
   }
 ],

 "Lookup": {
   "AttributeType": "Lookup",
   "AttributeTypeName": {
     "Value": "LookupType"
   },

   "Description": {
     "@odata.type": "Microsoft.Dynamics.CRM.Label",
     "LocalizedLabels": [
       {
         "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
         "Label": "Media Polymorphic Lookup",
         "LanguageCode": 1033
       }
     ],

     "UserLocalizedLabel": {
       "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
       "Label": " Media Polymorphic Lookup Attribute",
       "LanguageCode": 1033
     }
   },

   "DisplayName": {
     "@odata.type": "Microsoft.Dynamics.CRM.Label",
     "LocalizedLabels": [
       {
         "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
         "Label": "MediaPolymorphicLookup",
         "LanguageCode": 1033
       }
     ],

     "UserLocalizedLabel": {
       "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
       "Label": "MediaPolymorphicLookup",
       "LanguageCode": 1033
     }
   },

   "SchemaName": "new_mediaPolymporphicLookup",
   "@odata.type": "Microsoft.Dynamics.CRM.ComplexLookupAttributeMetadata"
 }
}

La réponse du JSON suivant est le corps de la réponse de la requêtes HTTP POST contenant l’ID de l’attribut polymorphe et toutes les relations créées.

{
    "@odata.context":
      "http://<organization URL>/api/data/v9.1/$metadata#Microsoft.Dynamics.CRM.CreatePolymorphicLookupAttributeResponse",

    "RelationshipIds":[
        "77d4c6e9-0397-eb11-a81c-000d3a6cfaba",
        "7ed4c6e9-0397-eb11-a81c-000d3a6cfaba",
        "85d4c6e9-0397-eb11-a81c-000d3a6cfaba"
    ],

    "AttributeId":"d378dd3e-42f4-4bd7-95c7-0ee546c7de40"
}

Utiliser les API de recherche multi-tables

Le tableau suivant répertorie les opérations pertinentes pour les définitions de table et d’attribut.

Opération
(méthode)
Description Format URL
Create
(POST)
Nouvelle API [OrganizationUrl]/api/data/v9.2
/CreatePolymorphicLookupAttribute
Récupérer l’attribut
(GET)
API existante [OrganizationUrl]/api/data/v9.2
/EntityDefinitions(<EntityId>)/Attributes(<AttributeId>)
Récupérer la relation
(GET)
API existante [OrganizationUrl]/api/data/v9.2
/RelationshipDefinitions(<RelationshipId>)
Ajouter la relation
(POST)
Ajoute une relation
à un attribut de
recherche polymorphe
attribut
[OrganizationUrl]/api/data/v9.2
/RelationshipDefinitions
Supprimer la relation
(DELETE)
API existante [OrganizationUrl]/api/data/v9.2
/RelationshipDefinitions(<RelationshipId>)
Supprimer l’attribut
(DELETE)
API existante [OrganizationUrl]/api/data/v9.2
/EntityDefinitions(<EntityId>)/Attributes(<AttributeId>)

Le tableau suivant répertorie les opérations pertinentes pour les données de table et d’attribut.

Operation
(méthode)
Description Format URL
Create
(POST)
Voir l’exemple new_checkouts suivant [OrganizationUrl]/api/data/v9.2
/<entitysetName>
Retrieve
(GET)
Ajouter l’en-tête suivant pour obtenir des annotations :

Content-Type: application/json
Préférez : odata.include-annotations="*"

[OrganizationUrl]/api/data/v9.2
/<entitysetName>(<recordId>)

L’exemple de requête suivant pour créer un enregistrement avec deux lignes.

POST [OrganizationUrl]/api/data/v9.1/new_checkouts
{
  "new_name": "c1",
  new_CheckedoutItem_new_book@odata.bind: "/new_books(387a2c9b-ecc6-ea11-a81e-000d3af68bd7)"
}

{
  "new_name": "c2",
  new_CheckedoutItem_new_device@odata.bind: "/new_devices(6472e7ba-ecc6-ea11-a81e-000d3af68bd7)"
}

Créer une recherche polymorphe (exemple de charge utile)

POST [OrganizationUrl]/api/data/v9.2/CreatePolymorphicLookupAttribute
{
  "OneToManyRelationships": [
    {
      "SchemaName": "new_checkout_poly_new_book",
      "ReferencedEntity": "new_book",
      "ReferencingEntity": "new_checkout"
    },
    {
      "SchemaName": "new_checkout_poly_new_device",
      "ReferencedEntity": "new_device",
      "ReferencingEntity": "new_checkout"
    },
    {
      "SchemaName": "new_checkout_poly_new_dvd",
      "ReferencedEntity": "new_dvd",
      "ReferencingEntity": "new_checkout",
      "CascadeConfiguration": {
        "Assign": "NoCascade",
        "Delete": "RemoveLink",
        "Merge": "NoCascade",
        "Reparent": "NoCascade",
        "Share": "NoCascade",
        "Unshare": "NoCascade"
      }
    }
  ],
  "Lookup": {
    "AttributeType": "Lookup",
    "AttributeTypeName": {
      "Value": "LookupType"
    },
    "Description": {
      "@odata.type": "Microsoft.Dynamics.CRM.Label",
      "LocalizedLabels": [
        {
          "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
          "Label": "Checkouted item Polymorphic Lookup Attribute",
          "LanguageCode": 1033
        }
      ],
      "UserLocalizedLabel": {
        "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
        "Label": "Checkedout item Polymorphic Lookup Attribute",
        "LanguageCode": 1033
      }
    },
    "DisplayName": {
      "@odata.type": "Microsoft.Dynamics.CRM.Label",
      "LocalizedLabels": [
        {
          "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
          "Label": "Checkedout item",
          "LanguageCode": 1033
        }
      ],
      "UserLocalizedLabel": {
        "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
        "Label": "Checkedout item",
        "LanguageCode": 1033
      }
    },
    "SchemaName": "new_CheckedoutItem",
    "@odata.type": "Microsoft.Dynamics.CRM.ComplexLookupAttributeMetadata"
  }
}

Ajouter une relation à la recherche polymorphe existante (exemple de charge utile)

POST [OrganizationUrl]/api/data/v9.2/RelationshipDefinitions
{
  "SchemaName": "new_checkout_poly_new_researchresource",
  "@odata.type": "Microsoft.Dynamics.CRM.OneToManyRelationshipMetadata",
  "CascadeConfiguration": {
    "Assign": "NoCascade",
    "Delete": "RemoveLink",
    "Merge": "NoCascade",
    "Reparent": "NoCascade",
    "Share": "NoCascade",
    "Unshare": "NoCascade"
  },
  "ReferencedEntity": "new_researchresource",
  "ReferencingEntity": "new_checkout",
  "Lookup": {
    "AttributeType": "Lookup",
    "AttributeTypeName": { "Value": "LookupType" },
    "Description": {
      "@odata.type": "Microsoft.Dynamics.CRM.Label",
      "LocalizedLabels": [
        {
          "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
          "Label": "Checkout Polymorphic Lookup Attribute",
          "LanguageCode": 1033
        }
      ],
      "UserLocalizedLabel": {
        "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
        "Label": "Checkout Polymorphic Lookup Attribute",
        "LanguageCode": 1033
      }
    },
    "DisplayName": {
      "@odata.type": "Microsoft.Dynamics.CRM.Label",
      "LocalizedLabels": [
        {
          "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
          "Label": "Checkout item",
          "LanguageCode": 1033
        }
      ],
      "UserLocalizedLabel": {
        "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
        "Label": "Checkout item",
        "LanguageCode": 1033
      }
    },
    "SchemaName": "new_CheckedoutItem",
    "@odata.type": "Microsoft.Dynamics.CRM.LookupAttributeMetadata"
  }
}

Voir aussi

Utiliser l’API web avec les définitions de table
Créer et mettre à jour des relations de table
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
Modèles de tables et de colonnes à l’aide de l’API web
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#)