totalCount error, number of items: 0 vs 1

Hi!

I´ve an error that I cannt resolve:

For this case, I load a grid with the data from my database. Then, I create a filter, and the error occurs when selecting a value that does not exist in the database for a column.

The query to the database returns 0 element and an empty list. But it seems that a record is loaded at null.


The code is:





And the ER answer:


Any idea where I could look?

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer
    Additionally - please post the code you have in "columns: {}", because I'm guessing your error message is related to how you have things set up in there.
  • Exactly!

    The problem was how the columns were defined in the grid. I was using the "index()" function, but Ive changed this for the function "foreach()" and now its working. Sometimes the function "index()" works well, sometimes no.. I dont know when I can use one or another. Only the "index()" function, if the query is empty and totalcount=0, gives a null row to the grid and crash. But the problem is solved! so thanks for everything!

     

    It doesnt work with the second "gridTextColumn()", but its running correctly when I changed it for a "foreach()" function (like the first one).

  • +1
    Certified Lead Developer
    in reply to Pablo Ramos Clemente

    There's your issue. When you do "index(local!data, "columnName", null())", then when the data subset is empty it will return a single (null) value, causing the error you saw. What you would want to do instead is "index(local!data, "columnName", {})" - as returning an empty set causes it to correctly show zero rows.  (a!forEach() smartly returns an empty set when the array it's given is empty, so it gets around this issue easily also.)

    (Incidentally, I also recommend using the property() function when pulling a named property from a CDT, and use index() when pulling an indexed position from an array. Both functions will work in either case, but it greatly helps readability of code in my experience when using them in the proper contexts.  So it would be "property(local!data, "columnName", {})".)

Reply
  • +1
    Certified Lead Developer
    in reply to Pablo Ramos Clemente

    There's your issue. When you do "index(local!data, "columnName", null())", then when the data subset is empty it will return a single (null) value, causing the error you saw. What you would want to do instead is "index(local!data, "columnName", {})" - as returning an empty set causes it to correctly show zero rows.  (a!forEach() smartly returns an empty set when the array it's given is empty, so it gets around this issue easily also.)

    (Incidentally, I also recommend using the property() function when pulling a named property from a CDT, and use index() when pulling an indexed position from an array. Both functions will work in either case, but it greatly helps readability of code in my experience when using them in the proper contexts.  So it would be "property(local!data, "columnName", {})".)

Children
No Data