AgileApps Support Wiki Pre Release

Difference between revisions of "ParametersIterator Class"

From AgileApps Support Wiki
imported>Aeric
 
imported>Aeric
m (Text replace - '// Error dialog' to '// Error message')
 
(4 intermediate revisions by the same user not shown)
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.


Line 6: Line 6:


The ParametersInterator class has following methods which you can call to manipulate the <tt>Parameters</tt> object:
The ParametersInterator class has following methods which you can call to manipulate the <tt>Parameters</tt> object:
:* [[#hasNext|<tt>hasNext</tt>]]
:* [[#next|<tt>next</tt>]]
:* [[#remove|<tt>remove</tt>]]


====hasNext====
====hasNext====
Line 27: Line 30:


  void remove()
  void remove()


''' ParametersIterator Class Example '''
''' ParametersIterator Class Example '''
Line 45: Line 47:
     // Some error happened.
     // Some error happened.
     String msg = "Account could not be retrieved";
     String msg = "Account could not be retrieved";
     Functions.debug(msg + ":\n" + result.getMessage()); // Log details
     Logger.info(msg + ":\n" + result.getMessage(), "Iterator"); // Log details
     Functions.throwError(msg + ".");                     // Error dialog
     Functions.throwError(msg + ".");                           // Error message
}
}
else if(resultCode == 0)
else if(resultCode == 0)
Line 66: Line 68:
}</syntaxhighlight>
}</syntaxhighlight>
|}
|}
<noinclude>


<noinclude>[[Category:Support Classes and Objects]]</noinclude>
[[Category:Support Classes and Objects]]
</noinclude>

Latest revision as of 22:30, 10 September 2013

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>