I want a subgrid on the Account form to be visible only for one Customer Type. Is that doable?
I want a subgrid on the Account form to be visible only for one Customer Type. Is that doable?
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.
Best Regards,
Leo
JS will not be able to do OOB grid read-only.
Thank you, Leo. Much appreciated.
Can JS also change a subgrid to read-only? Is that doable?
Thank you! (How do I mark as verified??)
Thank you for the detailed answer. I was hoping to avoid JS, but will use what works... this looks thorough.
Thank you. I was hoping to avoid JS, but I'll go with what works.
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.
2.About how to display/hide subgrid.
formContext.getControl(“gridname”).setVisible(false);
Best Regards,
Leo
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 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
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.
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,269 Super User 2024 Season 2
Martin Dráb 230,198 Most Valuable Professional
nmaenpaa 101,156