enable / disable section/tab/form v9+

Tel. 01489 666383

enable / disable section/tab/form v9+

14th March 2018 Uncategorised 0

// Section Disable

function sectiondisable (sectionname, disablestatus)
{
var ctrlName = Xrm.Page.ui.controls.get();
for(var i in ctrlName) {
var ctrl = ctrlName[i];
var ctrlSection = ctrl.getParent().getName();
if (ctrlSection == sectionname) {
ctrl.setDisabled(disablestatus);
}
}
} // sectiondisable

 

// TAB Disable

function tabdisable (tabname, disablestatus)
{
var tab = Xrm.Page.ui.tabs.get(tabname);
if (tab == null) alert(“Error: The tab: ” + tabname + ” is not on the form”);
else {
var tabsections = tab.sections.get();
for (var i in tabsections) {
var secname = tabsections[i].getName();
sectiondisable(secname, disablestatus);
}
}
} // tabdisable

 

//Form Disable

function formdisable(disablestatus)
{
var allAttributes = Xrm.Page.data.entity.attributes.get();
for (var i in allAttributes) {
var myattribute = Xrm.Page.data.entity.attributes.get(allAttributes[i].getName());
var myname = myattribute.getName();
Xrm.Page.getControl(myname).setDisabled(disablestatus);
}
} // formdisable

 

// All fields disable

function doesControlHaveAttribute(control) {
var controlType = control.getControlType();
return controlType != “iframe” && controlType != “webresource” && controlType != “subgrid”;
}

function disableFormFields(onOff) {
Xrm.Page.ui.controls.forEach(function (control, index) {
if (doesControlHaveAttribute(control)) {
control.setDisabled(onOff);
}
});
}

 

// Call

function setupForm(){
if (Xrm.Page.ui.getFormType() == 2 &&
Xrm.Page.getAttribute(“incidentstagecode”).getValue() != null &&
Xrm.Page.getAttribute(“incidentstagecode”).getValue() == “200001”)
{
disableFormFields(true);
}
}

 

credit to https://nothingnessit.wordpress.com/2014/06/25/crm2011-disable-enable-fields-sections-tabs-and-the-whole-form/

Leave a Reply

Your email address will not be published. Required fields are marked *