I have a couple of custom entities, which are linked together with a many to many relationship, using a linking entity which contains some linking attributes. For the sake of clarity let's call these Superhero and Supervillain, and the link will be Fight.
(Superhero) 1 --------- * (Fight) * -------- 1 (Supervillain)
That is, each fight is between 1 superhero and 1 supervillain, and each superhero/suppervillain combo can have any number of fights maybe of different type - sword, fist, etc.
All simple stuff so far. Effectively, what I'm doing here is reproducting the new "Connections" functionality, but using a custom linking type that only works with Superheros and Supervillains. The reason for this is I want to show these as a separate navigation item in the left hand side of the form, rather than lump them all in under "Connections".
Now, from the Superhero form, when I look at the related entities in the left hand pane, I want to show a see a list of the Fights, along with the Supervillain that the Superhero was fighting. Simple enough, I can just customise the "Fight Associated View" to show the type of Fight, and the Supervillain entity. This lets me click straight through from the Superhero to the Supervillain he was fighting.
But how about if I want to do the same from Supervillain? The same "Fight Associated View" is shown for Supervillains as well, but needs to be customised to show the fight type and the related Superhero... But, I don't want a "one size fits all" associated view, with both Superhero and Supervillain fields.
I want the associated view to change according to whether I'm looking at a Superhero or a Supervillain. So I create two new views, each with the desired columns. I can now manually switch to these view when selecting the related list in each entity. This works fine, but I don't want this manual step every time I look at the Related fights.
So, finally I get to the point of the question: How can I aut开发者_如何学编程omatically (i.e. through script, if necessary) select the default "Associated" view that will be shown for the Fights related to Superheros and Supervillains, dependent on the entity type?
Using form script, I can get the navigation item easily enough, but after that I am lost:
function SuperHero_OnLoad()
{
var fightItem = Xrm.Page.ui.navigation.items.get("nav_new_fight");
// What next?!
fightItem.MagicFunctionThatSelectsADefaultViewOrHacksIntoTheIframeParametersOrSomething();
}
Note: I know I can use a sub-grid in the main edit form, which lets you choose the view to display, but I don't want to clog the form up with more sub-grids. I want to use the Related tree on the left of the form.
ViewId in Customizations.xml does work, but you asked the question too early ;-) There was a bug which was resolved in Update Rollup 10 and above. I had the same problem until the update.
精彩评论