Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

JavaScript to show/hide sub-grid based on checkbox selection onload?

Posted on by Microsoft Employee

Hello,

Our organization uses Dynamics CRM 2015 on premise. I am attempting to create a javascript function within the Order entity to hide/show a custom entity subgrid based on a checkbox selection. I want this to occur on load at the moment, I may also implement it on change of that field if I can get it working this way first. Below is the script I have so far.

function hardwareIncluded(){
var HardwareStatus = Xrm.Page.getAttribute("new_hardwareincluded").getValue();
if(HardwareStatus == false)
{
Xrm.Page.ui.controls.get("HardwareShipments").setVisible(false);
}
else
{
Xrm.Page.ui.controls.get("HardwareShipments").setVisible(true);
}
}

In this script, "new_hardwareincluded" is the name of the two option field that is configured as a checkbox at the moment. "HardwareShipments" is the name of the subgrid within the Order form where this Javascript is being called on as an onload function. Below is an image of the error I am currently getting when I open an Order record, I tried with one that was checked and one that was not checked, same result. Any thoughts on this? Thanks!

Order-Javascript-Error.PNG

*This post is locked for comments

  • meenoo Profile Picture
    meenoo 7,316 on at
    RE: JavaScript to show/hide sub-grid based on checkbox selection onload?

    You are welcome. Glad it worked out. :)

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: JavaScript to show/hide sub-grid based on checkbox selection onload?

    meenoo,

    I really couldn't find anything wrong with the subgrid name I selected, if I open the details on that subgrid that's exactly what's listed under the name.

    That being said, using your code to hide/show an entire section worked perfectly. I think I'll just reorganize a bit and go that route instead of looking further into calling the subgrid. Thank you so much for your response, you saved me a bunch of time!

  • Verified answer
    meenoo Profile Picture
    meenoo 7,316 on at
    RE: JavaScript to show/hide sub-grid based on checkbox selection onload?

    Hi CRMUser13,

    Have you checked the subgrid name? Is it correct?

    Try to place subgrid in a section and make the section hide/show instead of subgrid.

    Like this:

    Xrm.Page.ui.tabs.get(TabName).sections.get(SectionName).setVisible(true);

    Thank you.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans