Documentation for common classes in the Javascript API.

sys.commons.ResultSet

An iterator over API service call results. ResultSet object maintains a cursor pointing to its current object. Initially the cursor is positioned before the first object. The next() method moves the cursor to the next available object.

The cursor moves forward only.

hasNext()

Checks if there are more objects.

Returns

boolean - true if there are more objects, false otherwise.

Samples

// prints the name of 10 companies

var query = sys.data.createQuery('companies').size(10);
var resultSet = sys.data.find(query);
while (resultSet.hasNext()) {
  var company = resultSet.next();
  log(company.label());
}

next()

Returns one object and moves the cursor forward.

Returns

object - Usually it is a sys.data.Record.

Exceptions

badRequest

If there are no more objects.

Samples

// prints the name of 10 companies

var query = sys.data.createQuery('companies').size(10);
var resultSet = sys.data.find(query);
while (resultSet.hasNext()) {
  var company = resultSet.next();
  log(company.label());
}

count()

Counts the number of objects matching the query. This does not take limit (_size param) into consideration.

Returns

number - The number of objects matching que query.

Samples

// counts number of companies of type 'a'

var query = sys.data.createQuery('companies').field('type').equals('a');
var resultSet = sys.data.find(query);
log('count: '+resultSet.count());

toArray()

Iterates over all objects and returns them as an array. If there are more than 1,000 objects, the method will throw an exception to avoid a memory overload.

Returns

object[] - Returns an array with all objects. These are usually objects of type sys.data.Record, but it depends one what you are iterating.

Exceptions

systemException

If there are more than 1,000 objects in the result set.

Samples

// prints the name of 10 companies

var query = sys.data.createQuery('companies').size(10);
var resultSet = sys.data.find(query);
var companies = resultSet.toArray();
companies.forEach(function(company) {
  log(company.label());
});

Back to top