AgileApps Support Wiki Pre Release

ParametersIterator Class

From AgileApps Support Wiki

The ParametersIterator class holds a list of Parameters objects returned by the searchRecords call. You can iterate through an instance of ParametersIterator to process Parameters objects one-by-one.

You create an instance of a ParametersIterator by making a getIterator call in the Result object.

Methods

The ParametersInterator class has following methods which you can call to manipulate the Parameters object:

hasNext

Returns true if there are more objects in the list, otherwise returns false. This method is used to iterate through a ParametersIterator object to get Parameters objects one-by-one.

Signature of the Method

boolean hasNext()

next

Gets the next Parameters object.

Signature of the Method

Parameters next()

remove

Removes the current Parameters object from the ParametersIterator object. Normally you do not need to call this.

Signature of the Method

void remove()

ParametersIterator Class Example

This example performs a search and if the search was successful and returned records, the code creates an instance of ParametersIterator. In a while loop, the code calls the ParametersIterator.next method to get an instance of Parameters from which it then extracts the name and number keys.

<syntaxhighlight lang="java" enclose="div"> String accountID = ""; // Some logic to populate accountID variable Result result = Functions.searchRecords("ACCOUNT", "record_id,name,number",

   "name contains 'Acme'");

int resultCode = result.getCode(); if(resultCode < 0) {

   // Some error happened.
   String msg = "Account could not be retrieved";
   Logger.info(msg + ":\n" + result.getMessage(), "Iterator"); // Log details
   Functions.throwError(msg + ".");                            // Error message

} else if(resultCode == 0) {

 // No records found. Take action according to your business logic

} else {

  //Records retrieved successfully
  ParametersIterator iterator = result.getIterator();
  while(iterator.hasNext())
  {
    Parameters myAccount = iterator.next();
    String accountID = myAccount.get("record_id");
    String accountName = myAccount.get("name");
    String number = myAccount.get("number");
    // Take action according to your business logic
  }

}</syntaxhighlight>