locked
FetchXml results count - Subgrid rows count in JavaScript RRS feed

  • Question

  • Hi! I have a fetchXml query and after do that, I send it to a sub grid, that should be hide if there are not returned records.

    I have seen in many blogs that can be added the returntotalrecordcount='true' property in the FetchXml query, but no one of them explains how to get the returned number. So it is worth this property?

    As I couldn't find out anything, I'm just trying to get the number of rows after doing the refresh to the grid, but all options that I have found, like these, doesn't give me back the number of rows.

    .get_selectedIds();  
    .getRecordsFromInnerGrid();
    .getElementsByTagName("span");

    I found other solutions like donwload the SDK Daniel Cai JavaScript, but do I have to modify my CRM solution just for this?


    Friday, March 15, 2013 12:10 PM

Answers

  • Hi,

    You try put with timeout like is mention in article i refer? The timeout is waiting that grid finish the load of records.

    Hope this helps.
    If i answered your question, please mark the response as an answer and also vote as helpful.


    Pedro Azevedo Crm Specialist 4.0\2011

    Friday, March 15, 2013 3:15 PM
  • Hi,

    Try reduce the timeout. In OnLoad call directly the function check_articles.

    Hope this helps.
    If i answered your question, please mark the response as an answer and also vote as helpful


    Pedro Azevedo Crm Specialist 4.0\2011

    Friday, March 15, 2013 4:35 PM

All replies

  • Hi,

    Did you see this solution?

    Hope this helps.
    If i answered your question, please mark the response as an answer and also vote as helpful.


    Pedro Azevedo Crm Specialist 4.0\2011

    Friday, March 15, 2013 12:39 PM
  • Hi Pedro!

    yes I tried

    var num = document.getElementById('grid_kb_articles').getElementsByTagName("span");
    alert(num.length);
    

    And give me back '18' having one record

    also this:

    var num =  grid.get_allRecordIds(); 
    alert(num.length);

    that returns '0'

    Friday, March 15, 2013 12:49 PM
  • Hi,

    But the solution is find the span:

    someGrid_ItemsTotal

    And see the text of that span. Is this solution that you try?

    Hope this helps.
    If i answered your question, please mark the response as an answer and also vote as helpful.


    Pedro Azevedo Crm Specialist 4.0\2011

    Friday, March 15, 2013 2:26 PM
  • Ok! I see now, my problem is that with grid_kb_articles_ItemsTotal and grid_kb_articles_TotalCountInfo, is giving me back 4, that are the total number of Articles, the entity where I'm doing the query.

    What I do is, after the query and refresh the grid, is access to it.

    var grid = document.getElementById('grid_kb_articles').control;
    grid.setParameter("fetchXml", fetchXml);
    grid.refresh();
    
    debugger;
    
    var spanList = document.getElementById('grid_kb_articles').getElementsByTagName("span");
        for (var i = 0; i < spanList.length; i++) {
            if (spanList[i].id != null && spanList[i].id == "grid_kb_articles_Itemstotal")
                alert(spanList[i].id + spanList[i].innerText);
    }
    
    Why I don't get 1 that is the number of records in the grid?

    Friday, March 15, 2013 3:08 PM
  • Hi,

    You try put with timeout like is mention in article i refer? The timeout is waiting that grid finish the load of records.

    Hope this helps.
    If i answered your question, please mark the response as an answer and also vote as helpful.


    Pedro Azevedo Crm Specialist 4.0\2011

    Friday, March 15, 2013 3:15 PM
  • No..I wasn't..I was doing it before doing the FetchXml to the grid, but I was missing the waiting after doing the FetchXml..not a good performance solution right? Thanks for your guidance!

    function Form_OnLoad() {
    check_subject();
    }
    
    function check_subject() {
        //Check if grid is avaliable
        setTimeout(check_articles, 10000);
    }
    
    function check_articles()
    {
        var fetchXml = "..."
         var grid = document.getElementById('grid_kb_articles').control;
         grid.setParameter("fetchXml", fetchXml);
         grid.refresh();
    
    
    chech_grid();
    
    
    }
    
    function chech_grid() {
     setTimeout(check_files, 10000);
    }
    
    
    function check_files() {
    
    var spanList = document.getElementById('grid_kb_articles').getElementsByTagName("span");
        for (var i = 0; i < spanList.length; i++) {
            if (spanList[i].id != null && spanList[i].id == "grid_kb_articles_ItemsTotal")
                alert(spanList[i].id + spanList[i].innerText);  }
    
    }
    
    
    

    Friday, March 15, 2013 3:48 PM
  • It is really slow having to wait two times for the grid to be ready..
    Friday, March 15, 2013 4:30 PM
  • Hi,

    Try reduce the timeout. In OnLoad call directly the function check_articles.

    Hope this helps.
    If i answered your question, please mark the response as an answer and also vote as helpful


    Pedro Azevedo Crm Specialist 4.0\2011

    Friday, March 15, 2013 4:35 PM
  • yes, I saw it..thanks again!! 

    PD. Actually I need it in the OnLoad call.

    Friday, March 15, 2013 5:28 PM