Showing posts with label Loop through subgrid records. Show all posts
Showing posts with label Loop through subgrid records. Show all posts

Wednesday, July 23, 2014

Loop through Subgrid records

function RetrieveSubGridRecords() {

    if (document.getElementById("SubgridId")) {

        var grid = document.getElementById("SubgridId").control;
        var totalBilled = 0;
        var totalUnBilled =0;
        for (var rowNo = 0; rowNo < grid.GetRecordsFromInnerGrid().length; rowNo++)
        {
           
            if(grid.GetRecordsFromInnerGrid()[rowNo][3].cells[7].outerText.indexOf("Yes") >= 0)
            {
                var numvalue = grid.GetRecordsFromInnerGrid()[rowNo][3].cells[6].outerText.replace(new RegExp(',', 'g'), '');
                alert(numvalue);
                totalBilled = totalBilled + parseFloat(numvalue);
                alert("yes"+totalBilled);
            }
            else
            {
                var numvalue = grid.GetRecordsFromInnerGrid()[rowNo][3].cells[6].outerText.replace(new RegExp(',', 'g'), '');
                alert(numvalue);
                totalUnBilled = totalUnBilled + parseFloat(numvalue);
                alert("no"+totalUnBilled);
            }
               
        }
        Xrm.Page.getAttribute("new_totalbilledamount").setValue(totalBilled);
        Xrm.Page.getAttribute("new_totalunbilledamt").setValue(totalUnBilled);        

    }

    else {

        setTimeout("RetrieveSubGridRecords();", 2500);

    }


}