Clean all fields in a Section- Js

Clean all fields in a Section- Js

Sometimes we might need to hide/show fields based on another field or hide/show sections based on any field or logic. But when we hide those fields or sections including the fields that they contain, we need also to clean the information they have. But a section might have many fields and it means there will be a big business rule to create or even a big js function to create. Below i will share a small snippet that can make that happen with less lines.


var tabNumber = ""
var sectionNumber = "";


function sectionClearFields(tabNumber, sectionNumber) {
? ? 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++) {
		Xrm.Page.getAttribute(controls[i].name).setValue();
? ? }
};        

You can use the same method also to enable/disable the fields :


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)
    }
}        

Happy Coding!

要查看或添加评论,请登录

Arjol Rrodhe的更多文章

社区洞察

其他会员也浏览了