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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

hide subgrid depending on field value?

(0) ShareShare
ReportReport
Posted on by

Hey!

I would like to hide a subgrid depending on what value a field is showing.

Is there a way to set an OnChange function to a field and hide a subgrid depending on that field?

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Rajkumar Rajaraman Profile Picture
    on at

    Hi Jonas,

    You want to find the schema name of the sub grid.

    You can do this by opening the form editor and then double clicking on the specific sub-grid.

    To retrieve your field value and based on condition you set the following way:

    To hide the sub-grid, you want to make sure to use supported JavaScript. To hide:

    Xrm.Page.ui.controls.get('Subgrid name').setVisible(false);

    To show:

    Xrm.Page.ui.controls.get('ProjectRisks').setVisible(true);

    Hope this helps.

    Regards,

    R.Rajkumar

    "Please mark my answer as verified if you found it helpful"

  • Community Member Profile Picture
    on at

    yes i've done that

    but how would the code look like if i wanted it to hide depending on a field value?

    Thanks for your help =)

  • Verified answer
    Rajkumar Rajaraman Profile Picture
    on at

    your depending field value as '1' then the sub grid would be enabling as,

    var field1 = Xrm.Page.getAttribute('depending field').getValue();

    if(field1 == 1)

    {

    Xrm.Page.ui.controls.get('Subgrid name').setVisible(true);

    }

    else

    {

    Xrm.Page.ui.controls.get('Subgrid name').setVisible(false);

    }

    Hope this helps.

    Regards,

    R.Rajkumar

    "Please mark my answer as verified if you found it helpful"

  • Community Member Profile Picture
    on at

    thank you friend. Just what i was looking for

  • Verified answer
    Royal King Profile Picture
    27,686 on at

    Place field and subgrid in 2 different sections in a form and attach onchange evet handler function to your optionset

    You can use below function has reference

    function showHideSection(PickListName, TabName,SectionName) {

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

       var zPicklistValue = Xrm.Page.getAttribute(PickListName).getValue();

       if (zPicklistValue != null) {

           if (zPicklistValue === 100002) {

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

           }

           else if(zPicklistValue === 100003) {

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

           }

       }

    }

  • Community Member Profile Picture
    on at

    Hi RajKumar,

    for example.. there is a section with 3 subgrids if I hide first two subgrids... there will be a  blank space left by the first two subgrids on the particular section of the form..

    Is there any way i can remove the empty space left by the subgrids and show the 3rd subgrid first in that particular section of the form ???

    Thanks

  • Community Member Profile Picture
    on at

    Where I can add this code ?

    sorry I'm new with this product.

    thanks

  • Suggested answer
    FrantisekCapek Profile Picture
    5 on at

    That's wrong, you should not use Xrm.Page since it is deprecated. Use formContext instead:

    docs.microsoft.com/.../getformcontext

    Also, it is good to use the switch statement since you can have multiple options in one field.

    Then, it will look like this:

    function HideSubgrid(executionContext){

       var formContext = executionContext.getFormContext();

       var parameter = formContext.getAttribute("FIELD NAME").getValue();

       var subGrid = formContext.getControl("GRID NAME");

       switch (parameter){

           case 1000001 :

               // either hide it or leave it

               subGrid.setVisible(false);

               break;

           case 1000002 :

               // either hide it or leave it

               break;

           // add more cases if needed

           default :

               // either hide it or leave it

               break;

       }

    }

    Happy coding!

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans