Monday, May 20, 2024
73
rated 0 times [  76] [ 3]  / answers: 1 / hits: 22638  / 10 Years ago, fri, july 11, 2014, 12:00:00

I need to disable a section if a value from other field is true, normally I would do:



function disableSection1(disabledStatus){
Xrm.Page.getControl(section1field1).setDisabled(disabledStatus);
Xrm.Page.getControl(section1field2).setDisabled(disabledStatus);
Xrm.Page.getControl(section1field3).setDisabled(disabledStatus);
Xrm.Page.getControl(section1field4).setDisabled(disabledStatus);
}


but i have to do this for many sections, so I am looking for a function like this:



function sectionSetDisabled(tabNumber, sectionNumber, disabledStatus){
//some code..
}

More From » dynamics-crm-2011

 Answers
19

Most answers I have seen you have use the use the sectionLable and do the following comparison:
controlIHave.getParent().getLabel()==name of the section



But after some trials I found I could use Xrm.Page.ui.tabs.get(tabNumber).sections.get(sectionNumber).controls.get() to get the controls inside the section. That allowed me to use the following function:



function sectionSetDisabled(tabNumber, sectionNumber, disablestatus) {
var section = Xrm.Page.ui.tabs.get(tabNumber).sections.get(sectionNumber);
var controls = section.controls.get();
var controlsLenght = controls.length;

for (var i = 0; i < controlsLenght; i++) {
controls[i].setDisabled(disablestatus)
}
}


by using controls[i].getAttribute() you can then get the attributes of a section.



I ended up creating a object that allows me to disable and clear all the fields in a section:



function sectionObject(tabNumber, sectionNumber) {
var section = Xrm.Page.ui.tabs.get(tabNumber).sections.get(sectionNumber);

this.setDisabled = function (disablestatus) {
var controls = section.controls.get();
var controlsLenght = controls.length;
for (var i = 0; i < controlsLenght; i++) {
controls[i].setDisabled(disablestatus)
}
};

this.clearFields = function () {
var controls = section.controls.get();
var controlsLenght = controls.length;
for (var i = 0; i < controlsLenght; i++) {
controls[i].getAttribute().setValue(null);
}
};

}

var section=new sectionObject(0,1);
section.setDisabled(true/false);

[#70227] Thursday, July 10, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
madalyngriseldas

Total Points: 167
Total Questions: 92
Total Answers: 85

Location: Iceland
Member since Sat, Sep 17, 2022
2 Years ago
;