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+

RSM Staff

RSM empowers middle market companies worldwide to take charge of change. Our unique middle market perspective makes RSM the natural choice for growth-oriented, internationally active organizations seeking relevant insights and tailored, innovative solutions for a complex and changing world. With a global reach spanning more than 120 countries, we instill confidence in a world of change by bringing the full power of RSM to make a lasting impact on our clients, colleagues and communities.

Contact our team to learn more!

Receive Posts by Email

Subscribe and stay aware of new posts by email.

Please Select Your Interests