web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Unanswered

Issue using custom JavaScript to change subgrid view

(0) ShareShare
ReportReport
Posted on by
Hi there,
 
I am attempting to change the view of a subgrid based on a field value. Naturally I can't just use a business rule, so I have decided to go the custom JS route to achieve this. This is the first time I have tried using custom JS within dynamics and have run into a problem I am unsure of how to solve. Here is my function(please ignore all the console logs):
function ChangeSubgridView(executionContext) {
 
    var gridViews = [
        {
            entityType: 1039,
            id: /B0B152E7-3154-4BEE-AC20-DB526501E1B4/,
            name: /Active Assessed Standards/
        },
        {
            entityType: 1039,
            name: /Active Assessed Standards (For Formulation Line)/
        }
    ]
 
    var formContext = executionContext.getFormContext();// get the form Context
    var gridContext = formContext.getControl('AssessedStandards'); //Get the Grid
    var viewSelector = gridContext.getViewSelector();
    console.log(viewSelector.getCurrentView());
 
    if(formContext.getAttribute('bg_productasingredient') != null){
        var isProduct = formContext.getAttribute('bg_productasingredient').getValue();// get the value of productasIngredient
        console.log(isProduct)
        if (isProduct) {
            console.log('equates to true, should change view')
            viewSelector.setCurrentView(gridViews[0]); //Set View to show assessed ingredients column
            console.log(viewSelector.getCurrentView())
   
        } else {
            console.log('equates to false, should not change view')
            viewSelector.setCurrentView(gridViews[1]);//Show default view
            console.log(viewSelector.getCurrentView())
   
        }
    }else{
        viewSelector.setCurrentView(gridViews[1]);//if null value show default view.
    }
}
 
The issue I am having is the object returned by getCurrentView() never changes, despite changing the default view through the powerapps form builder. It ONLY returns 
  1. entityType: /savedquery/
  2. id: /{B0B152E7-3154-4BEE-AC20-DB526501E1B4}/
  3. name: /Active Assessed Standards/
 
even if the default view is set to /Active Assessed Standards (For Formulation Line)/.
Both views are selected in the form builder as selectable views
It seems like I can only ever see the one view, and no matter what I do I can't get it to change the view or even return the other views object details. does anyone know why this is happening and how I can resolve this?
I have the same question (0)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Rishabh Kanaskar Profile Picture

Rishabh Kanaskar 149

#2
MVP-Daniyal Khaleel Profile Picture

MVP-Daniyal Khaleel 132

#3
Tom_Gioielli Profile Picture

Tom_Gioielli 123 Super User 2025 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans