AgileApps Support Wiki Pre Release

Difference between revisions of "ParametersIterator Class"

From AgileApps Support Wiki
imported>Aeric
imported>Aeric
Line 1: Line 1:
The <tt>ParametersIterator</tt> class holds a list of <tt>Parameters</tt> objects returned by the [[#searchRecords|<tt>searchRecords</tt>]] call. You can iterate through an instance of <tt>ParametersIterator</tt> to process <tt>Parameters</tt> objects one-by-one.
The <tt>ParametersIterator</tt> class holds a list of <tt>Parameters</tt> objects returned by the [[#searchRecords|<tt>searchRecords</tt>]] call. You can iterate through an instance of <tt>ParametersIterator</tt> to process <tt>Parameters</tt> objects one-by-one.
 
__NOTOC__
You create an instance of a <tt>ParametersIterator</tt> by making a [[#getIterator|<tt>getIterator</tt>]] call in the [[#Result Class|<tt>Result</tt>]] object.
You create an instance of a <tt>ParametersIterator</tt> by making a [[#getIterator|<tt>getIterator</tt>]] call in the [[#Result Class|<tt>Result</tt>]] object.



Revision as of 19:40, 13 October 2011

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";
   Functions.debug(msg + ":\n" + result.getMessage());  // Log details
   Functions.throwError(msg + ".");                     // Error dialog

} 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>