Thursday, May 22, 2014

Attach OnClick event in Sub grid Records MS CRM 2013 Using JavaScript

Sometimes we have requirements to attach click event to sub-grid. So we could read selected record data and do the stuffs.

Here is sample code to attach click event to sub grid :

function ReadSelectedSubGridRecords() {
    if (document.getElementById("SubGridName")) {
        var grid = document.getElementById("SubGridName").control;
        for (var rowNo = 0; rowNo < grid.get_selectedRecords().length; rowNo++)
            alert(grid.get_selectedRecords()[rowNo].Name);
    }
}

function Form_OnLoad() {
    if (document.getElementById("SubGridName")) {
        var grid = document.getElementById("SubGridName");
        // Google chrome
        if (grid.addEventListener) {
            grid.addEventListener('click', ReadSelectedSubGridRecords, false);
            // IE
        } else if (grid.attachEvent) {
            grid.attachEvent('onclick', ReadSelectedSubGridRecords);
        }

    }
    else {
        setTimeout("Form_OnLoad();", 2000);
    }
}

For more information please follow this BLOG

Read SubGrid Records in MS CRM 2013 using JavaScript

Many times we have requirements to read sub grid records and do subtotal or some others stuff with grid data. Here is same code to retrieve entire rows and columns from SubGrid.

function RetrieveSubGridRecords() {
    if (document.getElementById("SubGridName")) {
        var grid = document.getElementById("SubGridName").control;
        for (var rowNo = 0; rowNo < grid.GetRecordsFromInnerGrid().length; rowNo++)
            for (var cellNo = 0; cellNo < grid.GetRecordsFromInnerGrid()[rowNo][3].cells.length; cellNo++)
                alert(grid.GetRecordsFromInnerGrid()[rowNo][3].cells[cellNo].outerText);
    }
    else {
        setTimeout("RetrieveSubGridRecords();", 2500);
    }

}


Read selected SubGrid Records in MS CRM 2013 using JavaScript.

function ReadSelectedSubGridRecords() {
        if (document.getElementById("SubGridName")) {
        var grid = document.getElementById("SubGridName").control;
        for (var row = 0; row < grid.get_selectedRecords().length; row++)
            alert(grid.get_selectedRecords()[row].Name);
    }
}


Read sub-Grid cell value in MS CRM 2013 using Javascript.

function GetSubGridCellValues() {
    if (document.getElementById("SubGridName")) {
        var grid = document.getElementById("SubGridName").control;
        var ids = gridControl.get_allRecordIds();
        for (i = 0; i < ids.length; i++) {
            alert(gridControl.getCellValue('fullname', ids[i]));
        }
    }
    else {
        setTimeout("GetSubGridCellValues();", 2500);
    }


}

for more info please follow this BLOG

Split the String values with a special character in MS Flow to convert this into Array

 Many times we have a requirement to prepare the Mailing address for some of the documents, suppose there are Address Line1, Address Line2, ...