Polymorphic lookup delegation in Canvas Apps

By | November 13, 2020

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:

image

Well, if you are up to writing a little plugin, it’s, actually, quite doable:

image

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:

image

The plugin will convert this query into another one:

image

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:

image

We’ll need a plugin:

image

And we’ll need to register that plugin:

image

There you go. Don’t you ever forget about pluginsSmile

PS. And you will find the source code here: https://github.com/ashlega/ITAintBoring.PolymorphicDelegation

Leave a Reply

Your email address will not be published. Required fields are marked *