Announcements
No record found.
I want a subgrid on the Account form to be visible only for one Customer Type. Is that doable?
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.
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
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);
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
Thank you. I was hoping to avoid JS, but I'll go with what works.
Thank you for the detailed answer. I was hoping to avoid JS, but will use what works... this looks thorough.
Thank you! (How do I mark as verified??)
Thank you, Leo. Much appreciated.
Can JS also change a subgrid to read-only? Is that doable?
JS will not be able to do OOB grid read-only.
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/.../
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.
Congratulations to our 2026 Super Stars!
Thanks to all of our 2025 Community Spotlight stars!
These are the community rock stars!
Stay up to date on forum activity by subscribing.
Tom_Gioielli 30 Super User 2026 Season 1
NeerajPawar 22
Eugen Podkorytov 14