Friday, March 07, 2008

Hiding a Section

Hiding a section has been an interesting customization to figure out. I definitely got help by reading through posts and groups, but then again, who doesn't? When hiding things in CRM typically it's done by referencing a specific control name, something like the tab number or the field name. Sections are strange in that they don't have any of the normal "English" identifiers that one would expect. It's actually reference directly through a GUID. Each section gets assigned a GUID upon creation, so writing code that is dynamic for hiding sections directly really wasn't pretty...or possible.

However, if you reference a section indirectly things actually get much easier. For example, everything in the CRM forms are contained within something larger. Fields are contained by Sections, which are contained by Tabs, which are contained by the web form itself. That means that there is a direct parent/child relationship between objects on the form. JScript has thought about this and allows you to reference ParentNode's through code.

With this new knowledge referencing sections actually becomes very easy. All that has to be done is make a reference to a field on the form and then get it's parent node and do what you need to do to it.

Here's the code:

document.getElementById("ownerid") = "none";

You'll notice that I have to parentNode references, that's not a mistake, this is the progression on how to get to the section. Fields are actually contained by Labels and Labels are contained by Sections on a form. I didn't realize this until I tried using only the first parentNode reference. Play with it a bit and you'll see what I mean.

Then to make the section visible again just use empty quotes:

document.getElementById("ownerid") = "";

And now you have full control over what to make visible to users upon any condition you want.

Happy coding!

David Fronk
Dynamic Methods Inc.


Nate said...

That's a great post. I've always known how to hide fields and tabs, but never sections. This will made hiding multiple fields so much easier to code and mantain. Thank You!!!

Michael Dodd said...

Excellent Discovery. Will this work for 4.0??

Dynamic Methods said...


Absolutely. It works like a champ. Give it a try.

David Fronk
Dynamic Methods Inc.

Anonymous said...

Thanks for sharing this.

In my case I had to use 3 times parentNode to hide the section, apparently using it 2 times only removes the row where the control it's contained in.

Pete said...

Brilliant - I really have to learn the DOM - I'm sure there is much much more we can do similar to this.

Post a Comment