a!gridField returning error: A grid component [label=“”] has an invalid value for “value” and “totalCount”. “startIndex” must not be greater than “totalCount”, but “startIndex” was 51 and “totalCount” was 0.

Hi guys,

We're facing a bit of an issue in one of our gridFields. We have a search tab which retrieves and displays results in a gridField from an API. It searches and displays fine, but if we page past the first page and try to show 0 results (either by pressing a "Clear" button to clear the search or by searching for something with 0 results) we get the following error:

A grid component [label=“”] has an invalid value for “value” and “totalCount”. “startIndex” must not be greater than “totalCount”, but “startIndex” was 51 and “totalCount” was 0.

It seems to be caused by the startIndex not being reset, but as far as I know a!gridField should be handling this automatically. The gridField is populated with the following data:

if(
    rule!CMN_isBlank(
      local!searchResultData
    ),
    null,
    a!dataSubset(
      data: local!searchResultData,
      totalCount: local!metaData.totalRecords,
      startIndex: ri!searchParameters.startIndex,
      batchSize: ri!searchParameters.batchSize,
      sort: a!sortInfo(
        field: ri!searchParameters.sortColumn,
        ascending: ri!searchParameters.sortOrder
      )
    )
)


The local variables are all derived from the search response. To reduce load, the API we query only returns a max of 50 records at a time and a totalCount field. The totalCount field allows us to display the full number of results that match the query/allows the user to paginate. When we page, we query the API again for the next batch of results. Is there something wrong with the way we're trying to handle this which is causing our issue?

Thanks for any help, would really appreciate any insights into what's causing this problem.

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    The new paging grid component says it handles resetting of the start index automatically now, and when it works it works well - but I've found it only works in a very specific set of conditions.  Off the top of my head, I believe it only works when you're having the grid component manage paging for you, and will not work when you're handling the paging data yourself in any way.  As Danny already mentioned, we'd need to see more of your code in order to tell what the issue might actually be.

  • Thanks for the reply Mike. I've attached a larger code snippet in reply to Danny's comment which will hopefully provide more insight into what the problem might be. I guess it's probably down to us managing the paging manually in some way but I'm not familiar enough with how gridField's work to figure out what's causing it.

  • 0
    Certified Lead Developer
    in reply to johng0005

    As I suspected - you're manually setting the paging parameters in a way that the GridField won't be able to touch, so you'll need to make sure the startIndex is reset anytime you change filtering values, etc.

    I also don't think you need the if() statement checking for a null value on local!searchResultData, especially since when it's null then you'll be passing in a null value to the grid data parameter instead of a valid empty data subset.  But this probably isn't related to your original issue (it might cause different issues when the data set comes back empty, though).
    (EDIT: this might actually be part of the explanation behind your error, since you do seem to be manually resetting the StartIndex as needed in various spots)

    I'd suggest a further edit: instead of manually constructing a dataSubset on the data input of the grid using a!dataSubset, can you set a local variable to hold the dataSubset, and then use that in your data parameter?  This'll allow you to troubleshoot more easily as you'll be able to see it in the local variables list in the bottom-right panel.  Also I think you might want to use toDataSubset() instead, as it'll actually apply the paging information you provide, to the generated dataSubset.  AFAIK a!dataSubset() simply constructs a dataSubset object for you but doesn't handle paging or anything (but I haven't messed with it in a while, so don't quote me).

  • Thanks for the quick reply Mike, really appreciate it (and you've helped on numerous of my previous posts too, so thanks for that). I did try removing the if condition, but without it the interface loads with the following error:

    Interface Definition: Expression evaluation error at function a!gridField [line 219]: A null parameter has been passed.

    I also think you're right about the toDataSubset() function and the fact that it allows you to apply the paging information, the only issue with that is it doesn't seem to have a parameter for us to manually set the totalCount. Because we're only retrieving up to 50 records at a time (although there can be much more which we retrieve on each page) we need to manually set the totalCount otherwise the gridField assumes there's only up to 50 records in total and won't allow the user to page for more.

Reply
  • Thanks for the quick reply Mike, really appreciate it (and you've helped on numerous of my previous posts too, so thanks for that). I did try removing the if condition, but without it the interface loads with the following error:

    Interface Definition: Expression evaluation error at function a!gridField [line 219]: A null parameter has been passed.

    I also think you're right about the toDataSubset() function and the fact that it allows you to apply the paging information, the only issue with that is it doesn't seem to have a parameter for us to manually set the totalCount. Because we're only retrieving up to 50 records at a time (although there can be much more which we retrieve on each page) we need to manually set the totalCount otherwise the gridField assumes there's only up to 50 records in total and won't allow the user to page for more.

Children
  • +1
    Certified Lead Developer
    in reply to johng0005
    the only issue with that is it doesn't seem to have a parameter for us to manually set the totalCount.

    Gotcha - well the way you're doing it now should work as long as you keep tight control over what the resulting dataSubset object contains (at the end of the day, the result of both functions is just a dataSubset object, so it should be doable).  I still suggest moving it into a local variable, and making sure you get a dataSubset object whether or not the initial data array is empty.  As long as this is accomplished, you should not see the "null parameter" error on the grid that you quoted.

  • Hey Mike, thank you so much for the comments and help, finally got it working. Following what you said, I replaced the "null" value in the if condition you highlighted with an empty dataSubset object and now there's no issue when clearing the grid. 

    For anyone else who comes across this in future, as Mike suggested I moved the "if" condition that was creating the dataSubset directly in the a!gridField's "data" section to a local variable and changed the if true condition. Here's the code snippet:

      local!searchResultDataSubset: if(
        rule!CMN_isBlank(
          local!agreementData
        ),
        todatasubset(
          arrayToPage: {},
          pagingConfiguration: a!pagingInfo(
            1,
            50,
            null
          )
        ),
        a!dataSubset(
          data: local!agreementData,
          totalCount: local!metaData.totalRecords,
          startIndex: ri!searchParameters.startIndex,
          batchSize: ri!searchParameters.batchSize,
          sort: a!sortInfo(
            field: ri!searchParameters.sortColumn,
            ascending: ri!searchParameters.sortOrder
          )
        )
      )

    Thanks again Mike!

  • To add to all the great ideas, we always try to wrap API calls querying data into an expression which creates a datasubset out of the received data. There is at least one rule input for the pagingInfo. This helps to separate data preparation logic from interface logic.