CRM 2011 Javascript hide/show sections based on picklist

By - October 13, 2011

The following is a script for Microsoft Dynamics CRM will show and hide sections based on picklist value:

function HideShowHardwareRoles() {

var typeControl = Xrm.Page.ui.controls.get(“new_type”);
if ((typeControl != “undefined”) && (typeControl != null)) {
var picklist = Xrm.Page.data.entity.attributes.get(“new_type”);
if (picklist.getValue() != null) {
var hwText = Xrm.Page.getAttribute(“new_type”).getSelectedOption().text;
//set visible based on value
switch (hwText) {
case “Server/Workstation/Laptop”:
SetVisibleSection(“Server Roles”, true);
SetVisibleSection(“Router/Firewall Roles”, false);
SetVisibleSection(“Switch Roles”, false);
SetVisibleSection(“Printer Roles”, false);
break;
case “Router/Firewall”:
SetVisibleSection(“Server Roles”, false);
SetVisibleSection(“Router/Firewall Roles”, true);
SetVisibleSection(“Switch Roles”, false);
SetVisibleSection(“Printer Roles”, false);
break;
case “Switch”:
SetVisibleSection(“Server Roles”, false);
SetVisibleSection(“Router/Firewall Roles”, false);
SetVisibleSection(“Switch Roles”, true);
SetVisibleSection(“Printer Roles”, false);
break;
case “Printer”:
SetVisibleSection(“Server Roles”, false);
SetVisibleSection(“Router/Firewall Roles”, false);
SetVisibleSection(“Switch Roles”, false);
SetVisibleSection(“Printer Roles”, true);
break;
default:
SetVisibleSection(“Server Roles”, false);
SetVisibleSection(“Router/Firewall Roles”, false);
SetVisibleSection(“Switch Roles”, false);
SetVisibleSection(“Printer Roles”, false);
break;
}
}
else {
SetVisibleSection(“Server Roles”, false);
SetVisibleSection(“Router/Firewall Roles”, false);
SetVisibleSection(“Switch Roles”, false);
SetVisibleSection(“Printer Roles”, false);
}
}
}

function SetVisibleSection(sectionname, show) {
var tab = Xrm.Page.ui.tabs.get(“General”);
var section = tab.sections.get(sectionname);
if (section != null) {
section.setVisible(show);
}
}

By: Bill Caldwell – Microsoft Dynamics CRM Denver, Colorado Partner

Follow Bill on Google+

Bill Caldwell is a director and lead Microsoft Dynamics CRM consultant in the Denver, Colorado practice.  Bill is a certified Microsoft Dynamics CRM consultant and specializes in customizations, reports, customized queries and integrations.  Bill is an active member of the Dynamics community since joining RSM in 2007.  Bill is also experienced with the Microsoft development suites, which includes SQL Server, Visual Studio.Net and SQL Server Reporting Services.  Prior to this, Bill spent five years working in industry as an accountant and financial analyst. Contact Information: Email: Bill.Caldwell@rsmus.com Phone: 303.298.6465 Follow Bill on Google+

Receive Posts by Email

Subscribe and receive notifications of new posts by email.