Notifications
Announcements
No record found.
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
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"
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 =)
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
thank you friend. Just what i was looking for
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) {
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
Where I can add this code ?
sorry I'm new with this product.
thanks
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 :
// add more cases if needed
default :
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.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
SA-08121319-0 4
Calum MacFarlane 4
Alex Fun Wei Jie 2