DYNAMICS 365 HOW TO CHANGE SUBGRID SELECTED VIEW IN JAVASCRIPT

In other posts, we saw how to refresh a subgrid and how to filter a subgrid in JavaScript.

In this post, we will see how to change the view selected for the subgrid in JavaScript.

You can use this each time you need to display different columns in a sub grid based on a field value on the form because showing/hiding a column in a sub grid is not possible.
  1. Go to the entity form and open the form or field properties where you want to call the JavaScript function
  2. Under the Events tab, add the appropriate event handler and call the function that will change the subgrid view
  3. Save and Publish the form
  4. As outlined in the below JavaScript function, use the setCurrentView function to change the subgrid view.

    function changeSubgridView(context) {
    var formContext = context.getFormContext();
    // Get the gridContext
    var formContext = context.getFormContext();
    var gridContext = formContext.getControl("Contacts");
    var myActiveContacts = {
    entityType: 1039, // SavedQuery
    id: "00000000-0000-0000-00AA-000010001003",
    name: "My Active Contacts"
    }
    // Set the view
    gridContext.getViewSelector().setCurrentView(myActiveContacts);
    }


  5. Where
    • entityType represents a number for the type of view the user will select : savedQuery (1039) or userQuery (4230)
    • id represents the Guid of the view that will be selected and you can get it by going to the view customization and copying its Guid from the URL
      Dynamics 365 change subgrid view 1
    • name represents the name of the view that will be selected

At the end, and based on the conditions, the end result would be as follow
Dynamics 365 change subgrid view 2


Hope This Helps!

Comments

Popular posts from this blog

DISABLE ALL FORM FIELDS IN DYNAMICS 365 USING JAVASCRIPT

DYNAMICS 365 FILTER LOOKUP FIELD BASED ON N:N RELATIONSHIP

DYNAMICS 365 HOW TO REFRESH SUBGRID IN JAVASCRIPT