locked
Crm 2011: Javascript -> Select Row subgrid RRS feed

  • Question

  • Hy

     

    Is it possible to select a row from a subgrid within javascript?

     

    Thanks for your help,

    Peter


    • Edited by peter_wyss Friday, November 4, 2011 8:21 AM
    Friday, November 4, 2011 8:19 AM

All replies

  • Writing javascript that interacts with CRM subgrids to select a row is unsupported.  I will follow up with the feature team to see if this is something we can enable in the future.

    Perhaps you can describe your scenario further and maybe someone from the forums can provide a feasible workaround.

    Thanks for your suggestions!

    -Brandon

    Wednesday, November 9, 2011 2:53 AM
  • Hello folks,

     

    I have a similar need and will provide a scenario.

    I am involved in a CRM 2011 project for a financial institution.
    A typical banking service is Check Copy - an ability to request copies of one or more Check transactions.

    This particular financial institution archives their data after 45 days so the images are not always directly available and may require research to complete the request.
    A Check Copy Request entity has been created with a Transactions subgrid on the form with only a Checks View available so only check transactions can be selected.

    Goal: User selects one or more transactions in the subgrid, bank fees are calculated with each change in selected rows (this is the easy part) and the record is saved.
    When another user opens the record, the selections made are still present.

    The next person to open the Check Copy Request record does not see which checks are selected because the subgrid has no "memory" of which rows were originally selected.
    A hidden text field (called Selected Items) has been added to the Check Copy Request form that stores a CSV of selected row identifiers (not always guids - in this scenario Check Numbers are smaller than guids and are sufficiently distinct) and in the form load event, the selected items in the hidden field are used to select rows in the subgrid. (This is the part I have working, but it doesn't work right and a supported method would be really handy)

    I see that I can get a pointer to the grid control and/or the inner grid - and can work methods like "getSelectedRows", "moveRow", "getCellValue" ... but I don't see anything like "setSelectedRows", "SelectRow(rowId)", "selectRow(fieldName,FieldValue) - where I could identify a row by something other than the rowId"  or a collection or row items to loop through (found) that expose a get/set attribute for getSelected/setSelected (not found).

    I would appreciate any advice you might have to accomplish this, and would appreciate the feature team considering this as a future addition.

    Thank you,
    Tim D


    Timothy Darius
    Wednesday, December 21, 2011 7:43 PM
  • Here is the javascript code which will display the cell text of the selected rows fo the grid

    function ReadingGridControl() {
        var gridControl = document.getElementById('accountContactsGrid').control;
        for (var intRowNumber = 0; intRowNumber < gridControl.getRecordsFromInnerGrid().length; intRowNumber++)
            for (var intSelectedRows = 0; intSelectedRows < gridControl.get_selectedIds().length; intSelectedRows++)
                if (gridControl.get_selectedIds()[intSelectedRows] == gridControl.getRecordsFromInnerGrid()[intRowNumber][0]) {
                    for (var intCellNumber = 0; intCellNumber < gridControl.getRecordsFromInnerGrid()[intRowNumber][3].cells.length; intCellNumber++)
                        alert(gridControl.getRecordsFromInnerGrid()[intRowNumber][3].cells[intCellNumber].outerText);
                }
    }
    

    Hope that will help. Here accountContactGrid is the grid which is displayed on the account form.


    Please mark the replies as answers if they help. Asim Sajjad Software Engineer http://asimsajjad.blogspot.com
    Monday, January 2, 2012 10:32 AM
  • Thanks for posting this :) very helpful !!!!
    Tuesday, April 8, 2014 1:48 PM