I tried one of the lesser-known Dataverse features, “multi-table lookup columns”.
Multi-table lookup columns
One of Dataverse’s lesser-known features is the “Multi-table lookup” function.
This is a feature that allows multiple tables to be set up for a table’s search columns, which can be used to achieve polymorphic associations.
It is difficult to explain in words, so I explained with what I actually want to do and the operation.
What we want to do
*If I add a search column normally, I can only choose one of the tables.
*”Churu” is the name of a candy sold in Japan that cats love.
Implementation method
In this case, we will use the “multi-table lookup” function discussed at the beginning of this article to allow any of the three tables to be entered in the “Favorite Food” column of the “Cat” table.
At the time of this writing, “multi-table lookup” function can only be configured from the WebAPI or SDK (not from Power Apps Studio).
So this time, we will use Postman to set it up via WebAPI.
Using the API “CreatePolymophicLookupAttribute” from Postman
{ "OneToManyRelationships": [ { "SchemaName": "cr9cb_favorite_fish", "ReferencedEntity": "cr9cb_fish", "ReferencingEntity": "cr9cb_cat" }, { "SchemaName": "cr9cb_favorite_meat", "ReferencedEntity": "cr9cb_meat", "ReferencingEntity": "cr9cb_cat" }, { "SchemaName": "cr9cb_favorite_ciaochuru", "ReferencedEntity": "cr9cb_churu", "ReferencingEntity": "cr9cb_cat", "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": "Favorite food", "LanguageCode": 1041 } ], "UserLocalizedLabel": { "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel", "Label": "Favorite food", "LanguageCode": 1041 } }, "DisplayName": { "@odata.type": "Microsoft.Dynamics.CRM.Label", "LocalizedLabels": [ { "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel", "Label": "Favorite food", "LanguageCode": 1033 } ], "UserLocalizedLabel": { "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel", "Label": "Favorite food", "LanguageCode": 1033 } }, "SchemaName": "cr9cb_favorite_food", "@odata.type": "Microsoft.Dynamics.CRM.ComplexLookupAttributeMetadata" } }
*As you can see from the JSON, OneToManyRelationships defines all the relationships (cat and fish, cat and meat, cat and churu).
The setup is now complete.
Execution
Note: Adding is easy, but editing and deleting is hard!
But this “multi-table lookup column” is easy to [add], but hard to [edit] or [delete].
I tried various ways, but I couldn’t easily delete it, so it might be better to use it only when the table design is well defined.