// JavaScript CRM 2015 code
if (typeof (ZZSOFT) == “undefined”)
{ ZZSOFT = { __namespace: true }; }
if (typeof (ZZSOFT.CRM) == “undefined”)
{ ZZSOFT.CRM = { __namespace: true }; }
ZZSOFT.CRM.Common = {
//
// Disable all control inside the form
//
disableAllControls: function () {
Xrm.Page.data.entity.attributes.forEach(function (attribute, index) {
ZZSOFT.CRM.Common.disableCtrl(attribute.getName());
});
},
//
// Enable all control inside the form
//
enableAllControlss: function () {
Xrm.Page.data.entity.attributes.forEach(function (attribute, index) {
ZZSOFT.CRM.Common.enableCtrl(attribute.getName());
});
},
//
// Disable e single control on form and business process bar if it is present
// ctrlName = Control name
disableCtrl: function (ctrlName) {
var c = Xrm.Page.getControl(ctrlName);
if (c != null) {
c.setDisabled(true);
}
var hpc = Xrm.Page.getControl(“header_process_” + ctrlName);
if (hpc != null) {
hpc.setDisabled(true);
}
},
//
// Enable single control on form and business process bar if it is present
// ctrlName = Control name
enableCtrl: function (ctrlName) {
var c = Xrm.Page.getControl(ctrlName);
if (c != null) {
c.setDisabled(false);
}
var hpc = Xrm.Page.getControl(“header_process_” + ctrlName);
if (hpc != null) {
hpc.setDisabled(false);
}
},
//
// Hide single control on form and business process bar if it is present
// ctrlName = Control name
hideCtrl: function (ctrlName) {
var c = Xrm.Page.getControl(ctrlName);
if (c != null) {
c.setVisible(false);
}
var hpc = Xrm.Page.getControl(“header_process_” + ctrlName);
if (hpc != null) {
hpc.setVisible(false);
}
},
//
// Show single control on form and business process bar if it is present
// ctrlName = Control name
showCtrl: function (ctrlName) {
var c = Xrm.Page.getControl(ctrlName);
if (c != null) {
c.setVisible(true);
}
var hpc = Xrm.Page.getControl(“header_process_” + ctrlName);
if (hpc != null) {
hpc.setVisible(true);
}
},
//
// Hide section
// sectionName = Name of the section
hideSection: function (sectionName) {
var tabs = Xrm.Page.ui.tabs.get();
for (var i in tabs) {
var tab = tabs[i];
tab.sections.forEach(function (section, index) {
if (section.getName() == sectionName) {
section.setVisible(false);
}
});
}
},
//
// Show section
// sectionName = Name of the section
showSection: function (sectionName) {
var tabs = Xrm.Page.ui.tabs.get();
for (var i in tabs) {
var tab = tabs[i];
tab.sections.forEach(function (section, index) {
if (section.getName() == sectionName) {
section.setVisible(true);
}
});
}
},
//
// Hide tab
// tabName= Name of the tab
hideTab: function (tabName) {
var tabs = Xrm.Page.ui.tabs.get();
for (var i in tabs) {
var tab = tabs[i];
if (tab.getName() == tabName) {
tab.setVisible(false);
}
}
},
//
// Show tab
// tabName= Name of the tab
showTab: function (tabName) {
var tabs = Xrm.Page.ui.tabs.get();
for (var i in tabs) {
var tab = tabs[i];
if (tab.getName() == tabName) {
tab.setVisible(true);
}
}
},
__namespace: true
}
Dynamics CRM 2015 : some simple javascript function
Leave a reply