Changing Field, Section, and Tab names from a radio button in Dynamics CRM 4.0

Paul Nieuwelaar, 28 July 2010

In this post I will describe how to change a field name, section name, or even tab name based on the selection of a radio button. As you can see below, what we will be achieving is selecting Customer or Supplier from the Contract Type radio button, which will change the Tab, Section and Field name accordingly.

The first thing to do is to create a radio button. For the purposes of this post I will call it new_contracttype.

NOTE: It is a good idea to publish the entity once you have created the radio button, otherwise it won’t appear properly on the create form.

Now open the form, and add the radio button that you just created. Then select the radio button, click Change Properties, and open the onChange event.

Check that Event is enabled, and then add the following lines of code.

if (crmForm.all.new_contracttype.DataValue == true) {

 

    // Change the Tab name

    crmForm.all.tab0Tab.innerText = "Supplier";

 

    // Change the Section name

    crmForm.all.title.parentElement.parentElement.parentElement.children[0].childNodes[0].innerText = "Supplier Information";

 

    // Change the Field name

    crmForm.all.customerid_c.innerHTML = "Supplier";

}

else {

    // Change the Tab name

    crmForm.all.tab0Tab.innerText = "Customer";

 

    // Change the Section name

    crmForm.all.title.parentElement.parentElement.parentElement.children[0].childNodes[0].innerText = "Customer Information";

 

    // Change the Field name

    crmForm.all.customerid_c.innerHTML = "Customer";

}

 


Change where it has new_contracttype to be the radio button’s name.

Under Tab name:
Change 0 to be the tab number you are changing, and Supplier/Customer to the text you are changing between.

NOTE: Tab 0 is the first tab.

Under Section name:
Where it has title, that is the name of any text field located under the section, and Supplier Information/Customer Information is the text you are changing between.

Under Field name:
customerid is the field name to change the name of, and Supplier/Customer is the field name you are changing between.

NOTE: When you change the field name it will remove the Business Required or Business Recommended symbol (but will not actually change the requirement level), and also when you hover over the name, it will only show one name, even when the other is displaying.

Once you have tested that it does what is expected by viewing the create form, add one final line of code to the forms onLoad event, which will fire the radio buttons onChange, so that the Field, Section, and Tab names are always correct.

crmForm.all.new_contracttype.FireOnChange();

Test that form loads without any errors, and that it functions as it should. When you’re happy with the result publish the entity and you’re done. Feel free to modify it to suit yourself.