Hide A Tab based upon Account Type
After seeing some of our top partners such as Invoke and ePartners demo this functionality, I was dying to see how they did it. Then Simon Hutson posted on his blog a script to hide a tab based upon an account being a partner or a customer. Well, after seeing both scripts, both where awesome, but both had their drawbacks. Simon used OnLoad and ePartners used OnChange. What are the pros and cons?
Before we start with the pro's and con's, lets go through the three options available to you. The three scripting events you can have events fire on are, OnLoad, OnChange and OnSave.
Onload:
- The Onload event occurs after the form has loaded; it cannot prevent the window from loading. The OnLoad event is valuable because it can apply logic about how the form should be displayed and can be used to set certain fields to read-only or business required.
OnChange:
- The OnChange event is fired when the data in a form field has changed and focus is lost. The Microsoft CRM 3.0 application processes the OnChange event first and the data in the field is validated again following the execution of your OnChange event code.
OnSave:
- This event does not correspond to the standard OnSave event exposed by DHTML. It is fired when a user presses the Save or Save and Close button on the form. The event is fired whether the data in the form has been modified or not.
- Validating data is a common reason to use the OnSave event. The OnSave event can cancel the save operation before it is sent back to the server. To cancel the save operation, the script should return false as shown in the following code.
So now onto Pros and Cons... :-)
With OnLoad, when the form is loaded the conditions are evaluated and the action is carried out. So if a account goes from Prospect to Customer, the tab would not be hidden until the form is reloaded. So that would require the user to save and close the window and then open back up to get the tab to show up as hidden. So if an account never moves, then this method alone would do the job for you.
With OnChange, when you change the value the condition is evaluated and the action is carried out. Once you change somebody to a supplier that tab would only be hidden while that form was open. So if you change the value, it will hide the tab, but if you save and open the form back up, the tab is back.... So OnChange works to give the user immediate feedback.
So with a little bit of time and some help from Paul Reitmeyer from Invoke, we created two scripts that handles both scenarios. How you ask? But using both the OnLoad and OnChange Events, we can play to the strengths in each of them.
So we are going to use a new tool today. Here are the steps required to hide tabs when a account opens and the picklist changes. :-)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( window.document.forms( "crmForm" ).elements( "customertypecode" ).SelectedText == "Supplier" || window.document.forms( "crmForm" ).elements( "customertypecode" ).SelectedText == "Customer") { crmForm.all.tab1Tab.style.display="none"; } |
|
|
|
|
|
|
|
if (crmForm.all.customertypecode.SelectedText == "Customer" || crmForm.all.customertypecode.SelectedText == "Supplier") { crmForm.all.tab1Tab.style.display="none"; }
|
|
|
|
|
|
|
|
An Account with the Relationship Type of Investor
The Same Account with the Relationship Type of Customer
These scripts could use some further enhancements. (I see one little hole already... Change it from a Customer to a Prospect... The form doesn't refresh... So the script needs a little more work...) What would you like to see in some future script examples?