Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Dynamics 365 general forum

JavaScript to hide sub-grid not working in model app, but works in classic?

(0) ShareShare
ReportReport
Posted on by 65

Wondering if someone can help with this. I am using the below JavaScript which works fine in the classic interface, but does not do anything when viewing the same record in the "Sales Hub" / Model Apps. I have checked the browser console and there are no errors etc...

Any idea why the below will not run in the "Sales Hub" / Model Apps?

var isthething = Xrm.Page.getAttribute('fieldwiththething').getValue();

if (isthething == '181870000') {

    Xrm.Page.ui.controls.get('SubG1').setVisible(false);
    Xrm.Page.ui.controls.get('SubG2').setVisible(false);
    Xrm.Page.ui.controls.get('SubG3').setVisible(false);
    Xrm.Page.ui.controls.get('SubG4').setVisible(false);
  
  }

else {

    Xrm.Page.ui.controls.get('SubG1').setVisible(true);
    Xrm.Page.ui.controls.get('SubG2').setVisible(true);
    Xrm.Page.ui.controls.get('SubG3').setVisible(true);
    Xrm.Page.ui.controls.get('SubG4').setVisible(true);

}


  • Suggested answer
    dvn92 Profile Picture
    dvn92 65 on at
    RE: JavaScript to hide sub-grid not working in model app, but works in classic?

    Thank you so much - this helped point me in the right direction (I was not aware of the "Xrm.page" and "ExecutionContext.getFormContext" changes) and also using community.dynamics.com/.../302873 I was able to get this working properly.

  • Verified answer
    LeoAlt Profile Picture
    LeoAlt 16,331 Moderator on at
    RE: JavaScript to hide sub-grid not working in model app, but works in classic?

    Hi partner,

    "Xrm.page" is only available in classic web, if you want to use js in UI, you should use "ExecutionContext.getFormContext()" instead.

    For example, I want to hide the "Project Price List" in Account form in UI, I could use the following code.

    function hidesub(ExecutionContext){
    
         ExecutionContext.getFormContext().ui.controls.get('PriceListsGrid').setVisible(false);
    
    }

    3225.community434.png

    3225.community434.png

    Remember to select "Pass execution context as first parameter" when adding function to Onload event.

    So in your case, you should replace "Xrm.page" with "ExecutionContext.getFormContext" and try again.
    Hope it helps.
    Best Regards,
    Leo

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,430 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans