0
votes

I have a datasource that contains > 1000 records. The current Query page size is at 100.

I have a need to loop through each item, and try to find a record that matches input given by the user. Fairly simple use-case, however, I can't seem to get the script to loop through the pages so it just finishes its loop at the query page size of 100 and therefore only searching the first 100 records.

I've tried putting in

app.datasources.Vehicles.nextPage();

at the end of the for loop and then call regoExists again with the new page but it doesn't work. How is nextPage() meant to be used in client scripts?

function regoExists(rego){
  var regoUp = rego.toUpperCase();
  regoUp = regoUp.trim(); 

  ds = app.datasources.Vehicles.items;

  for (var i in ds){
    if (ds[i].registration === regoUp){
      console.log(ds[i].registration + " equals " + regoUp);
      app.datasources.Vehicles.query.filters.registration._equals = regoUp;
      return true;
    } else {
      console.log(ds[i].registration + " does not equals " + regoUp);
      continue;
    }
  }
} 
1
Might I inquire why you would not just use a regular query for this instead of looping through each record and performing a query on each individual record? Not sure where you are calling your function, but this could be accomplished by introducing a textbox widget, setting the binding to datasource.query.filters.registration._equals and you can either load the datasource with a button click or on the onValueEdit event of the textbox widget. - Markus Malessa
You're completely right. I have no idea why I didn't just query it and then check to see if the item actually exists. I ended up finding a solution along this train of thought. Can you answer the question so I can mark as answered. - Elias W
Added the suggestion as an answer. Thank you. - Markus Malessa

1 Answers

1
votes

Rather than looping through each record and performing the query on each individual record I would suggest introducing a textbox widget in the same datasource and setting the binding to:

@datasource.query.filters.registration._equals

Then load the datasource via a button click or via the onValueEdit event of the textbox widget. If the registration value exists, it will be returned in a table presumably, and if it doesn't exist no records would be returned.