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 :
Service | Customer Service, Contact Center, Fie...
Answered

Subgrid: Can it be conditional?

(0) ShareShare
ReportReport
Posted on by

I want a subgrid on the Account form to be visible only for one Customer Type.  Is that doable?

I have the same question (0)
  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello Andy,

    That's doable. Place your grid to separated section and show/hide that section based on the value of Customer Type using JavaScript.

  • SamiraM Profile Picture
    587 on at

    Hi Andy,

    Yes it is completely doable. As Andrew ha suggested place that subgrid in the section and show hide that section. Below is the sample code for the same.

    function ShowHidesection(executioncontext) {

       try {

           formContext = executioncontext.getFormContext();

           var clientKyc = formContext.getAttribute("customertype").getValue();

           if (clientKyc != null && clientKyc == 100000000) {

                  formContext.ui.tabs.get("DETAILS_TAB").sections.get("CONTACT_PREFERENCES").setVisible(false);

           }

           else {

               formContext.ui.tabs.get("DETAILS_TAB").sections.get("CONTACT_PREFERENCES").setVisible(true);

           }

       }

       catch (ex) { }

    }

    Please verify if you like the answer.

    Regards,

    Samira

  • Suggested answer
    Pawar Pravin  Profile Picture
    5,237 on at

    Yes, you can achieve this by creating custom JavaScript function.

    1. Add subgrid in one section

    2. On onload of form check if customer type is the expected one to whom you want to show section.

    e.g.

    Xrm.Page.ui.tabs.get(“SubGridname”).sections.get(“sectionname”).setVisible(true/false);

  • Verified answer
    LeoAlt Profile Picture
    16,331 Moderator on at

    Hi partner,

    It is possible with JS code.

    You should create a method to get the current user type by JS and then according this to display/hide the subgrid.

    1.How to get the user information.

    If you are using D365 V9.X, you could use Web api.

    function getValueFromOwnerLookUp(executionContext){
        var formContext=executionContext.getFormContext();
        //get correct userid
        var userid= Xrm.Utility.getGlobalContext().userSettings.userId;
        if(userid!=null){
            //use record id to retrieve other field value
            Xrm.WebApi.retrieveRecord("systemuser",userid,"?$select=type").then(
                function success(result){
                    //get the systemuser field value and set it to field on case
                    var fieldValue=result.fieldname;
                    formContext.getAttribute("fieldname").setValue(fieldValue);
                },
                function (error){
                    console.log(error.message);
                }
            )
    
        }
        
    }

    If you are using other versions, you could refer to the following thread.

    https://community.dynamics.com/crm/f/microsoft-dynamics-crm-forum/291510/show-hide-the-subgrid-based-on-the-user-role?pifragment-97030=1#responses

    2.About how to display/hide subgrid.

    formContext.getControl(“gridname”).setVisible(false);

    Best Regards,

    Leo

  • Suggested answer
    Community Member Profile Picture
    on at

    Thank you.  I was hoping to avoid JS, but I'll go with what works.

  • Suggested answer
    Community Member Profile Picture
    on at

    Thank you for the detailed answer.  I was hoping to avoid JS, but will use what works... this looks thorough.

  • Suggested answer
    Community Member Profile Picture
    on at

    Thank you!  (How do I mark as verified??)

  • Suggested answer
    Community Member Profile Picture
    on at

    Thank you, Leo.  Much appreciated.

    Can JS also change a subgrid to read-only?  Is that doable?

  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    JS will not be able to do OOB grid read-only.

  • LeoAlt Profile Picture
    16,331 Moderator on at

    Hi partner,

    Thanks for your recognition and unfortunately we could not use JS code to set the subgrid to read-only.

    But you could hide the add button in subgrid by ribbonworkbench.

    carldesouza.com/.../

    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

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 > Service | Customer Service, Contact Center, Field Service, Guides

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 73 Super User 2025 Season 2

#2
Siv Sagar Profile Picture

Siv Sagar 52 Super User 2025 Season 2

#3
Daniyal Khaleel Profile Picture

Daniyal Khaleel 42 Most Valuable Professional

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans