Right on the heels of my previous post where I was talking about delegation in Canvas Apps, here is another one on the same topic.
We can’t help but break delegation when filtering polymorphic lookups, right? Since, of course, “AsType” cannot be delegated:
Well, if you are up to writing a little plugin, it’s, actually, quite doable:
The idea is very simple:
- Let’s create a dummy field (“Dummy Account Name”)
- Let’s create a plugin to kick in on RetrieveMultiple
- And let’s update the query in the pre-operation so that the filter we specify for the “Dummy Account Name” is converted into a filter on the linked account entity
In other words, in the pre-operation, the plugin will receive this query:
The plugin will convert this query into another one:
And the rest of the execution pipeline will work as is.
So, to start with, we’ll need to add “Dummy Account Field” to the contact entity:
We’ll need a plugin:
And we’ll need to register that plugin:
There you go. Don’t you ever forget about plugins
PS. And you will find the source code here: https://github.com/ashlega/ITAintBoring.PolymorphicDelegation