Dynamics 365 - Creating a view on runtime and assign it to the subgrid lookup field
Recently during one of the tasks I was doing, I came up with a problem where I had to filter a lookup on a subgrid (for example Entity2) based on a value in another lookup (for example Entity1) on a Case form. If I had to filter the lookup on a subgrid for Entity2 for Case then that feature is available out of the box. For understand the example see following screen shot: The lookup highlighted above needs to be filtered based on the value in the lookup of Entity1. Here in this example Entity1 and Entity2 are related to each other with N-N relationships. Following javascript code can be used to achieve this task. You need to call this function on form's OnLoad event. function filterLookup() { var subgridAddButtonId = "Entity2_addImageButton"; //Try to get the element from both the current and the parent document. var subgr...