Dynamics 365





Wednesday, September 11, 2013

SubGrid Refresh or SubGrid Attach even usig Java Script

 below peice of code to refresh the subgrid.
 
function SubGridLoadWait() {
    setTimeout(OnAccountFormLoad, 3000);
}

function OnAccountFormLoad() {
    //Set Action on subgrid Refresh
    //debugger;
    var subGrid = document.getElementById("SuspectGrid");
    //if(subGrid) {
    subGrid.attachEvent("onrefresh", getPrimaryRows);

    //SubGrid.attachEvent("onrefresh", CallbackFunction);
    //SubGrid.control.add_onRefresh(CallbackFunction);

    //}

}

//This function fires on subgrid refresh

function getPrimaryRows() {
    var isPrimaryYes = false;
    var isPrimaryNo = false;
    var gridControl = document.getElementById('SuspectGrid').control;
    var ids = gridControl.get_allRecordIds();
    for (i = 0; i < ids.length; i++) {

        var primary = gridControl.getCellValue('new_isprimarysuspect', ids[i]);
        if (primary=="Yes") {
            isPrimaryYes = true;
            break;
        }
        else if(primary=="No"){
            isPrimaryNo = true;
        }
    }
    if (isPrimaryYes) {

        Xrm.Page.getAttribute("new_canhaveprimarysuspect").setValue(true);
//        alert("Primary Suspect checked");
    }
    else if (isPrimaryNo) {
        Xrm.Page.getAttribute("new_canhaveprimarysuspect").setValue(false);
      //  alert("Primary Suspect unchecked");
    }
}

No comments:

Post a Comment