In this recipe, we will focus on executing a few operations triggered by the form load event. We can check the value of a specific field on the form, and based on that we can decide to hide a tab, hide a field, and prepopulate a text field with a predefined value.
Just as with any of the previous recipes, you will need access to an environment, and permissions to make customizations. You should be a system administrator, a system customizer, or a custom role configured to allow you to perform the following operations.
For the purpose of this exercise, we will add to the Contact entity a new tab called "Special Customer", with some additional custom fields. We will also add an option set that we will check to determine if we hide or not the fields, as well as two new fields: one text field and one lookup field. So let's get started!
Special Customer
.function IsSpecialCustomer() { var _isSpecialSelection = null; var _isSpecial = Xrm.Page.getAttribute("new_isspecialcustomer"); if(_isSpecial != null) { _isSpecialSelection = _isSpecial.getValue(); } if(_isSpecialSelection == false) { // hide the Special Customer tab Xrm.Page.ui.tabs.get("tab_5").setVisible(false); // hide the Customer Classification field Xrm.Page.ui.controls.get("new_customerclassification").setVisible(false); // hide the Partner field Xrm.Page.ui.controls.get("new_partner").setVisible(false); } }
Form OnLoad
add the function we created:The whole idea of this script is not much different from what we have demonstrated in some of the previous recipes. Based on a set form value, we hide a tab and some fields. Where we capture the difference is where we set the script to execute. Working with scripts executing when the form loads gives us a whole new way of handling various scenarios.
In many scenarios, working with the form load events in conjunction with the other field events can potentially result in a very complex solution.
3.145.83.222