Wednesday, July 14, 2021

How to search in multiple table from a lookup in Dynamic CRM

Now we can use a single lookup field to refer multiple entities for searching (including a custom entity)

A lookup value submitted will be matched to a record in all the related entities.

Note: For now, to achieve this it is possible only via SDK or Web APIs. Interactive user interface support will be coming in a future release. 

Example:

Let's say you are hosting media for users in a library. You have many different MediaObjects, like “Books”, “Audio”, and “Video”. Creating a multi-table lookup called “new_Media” that has 1:M relationships to “new_Books”, “new_Audio”, and “new_Video” will result in a “new_Media” lookup table that provides quick identifications of records stored in specific tables.

 



Shown below is an HTTP post to CREATE Multiple lookup attribute.

It will create three relationships as depicted below image.


POST [Organization URI]/api/data/v9.0/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"

 }

}



Add new relationship to existing Multiple-lookup

POST [OrganizationUrl]/api/data/v9.0/RelationshipDefinitions

{

  "SchemaName": "new_media_poly_new_newspaper",

  "@odata.type": "Microsoft.Dynamics.CRM.OneToManyRelationshipMetadata",

  "CascadeConfiguration": {

    "Assign": "NoCascade",

    "Delete": "RemoveLink",

    "Merge": "NoCascade",

    "Reparent": "NoCascade",

    "Share": "NoCascade",

    "Unshare": "NoCascade"

  },

  "ReferencedEntity": "new_newspaper",

  "ReferencingEntity": "new_media",

  "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.LookupAttributeMetadata"

  }

}


Finally, we can see all entities in lookup





References

https://powerapps.microsoft.com/en-us/blog/announcement-multi-table-lookups-are-now-available-as-a-preview/

https://docs.microsoft.com/en-us/powerapps/developer/data-platform/webapi/multitable-lookup?branch=pr-en-us-4448


No comments: