Skip to main content

Notifications

Announcements

No record found.

Service | Customer Service, Contact Center, Fie...
Answered

Subgrid: Can it be conditional?

Posted on by Microsoft Employee

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

  • LeoAlt Profile Picture
    LeoAlt 16,329 on at
    RE: Subgrid: Can it be conditional?

    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

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Subgrid: Can it be conditional?

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

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Subgrid: Can it be conditional?

    Thank you, Leo.  Much appreciated.

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

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Subgrid: Can it be conditional?

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

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Subgrid: Can it be conditional?

    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
    Community Member Microsoft Employee on at
    RE: Subgrid: Can it be conditional?

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

  • Verified answer
    LeoAlt Profile Picture
    LeoAlt 16,329 on at
    RE: Subgrid: Can it be conditional?

    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
    Pawar Pravin  Profile Picture
    Pawar Pravin 5,227 on at
    RE: Subgrid: Can it be conditional?

    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);

  • SamiraM Profile Picture
    SamiraM 571 on at
    RE: Subgrid: Can it be conditional?

    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
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Subgrid: Can it be conditional?

    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.

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!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans