Function to Retrieve Account Object Data

From LongJump Support Wiki
Revision as of 18:59, 23 May 2011 by imported>Aeric
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Warn.png

DEPRECATED: Old example.


This example gets credit rating data in an account record.

// Function: getAccountCreditRating
// The function takes an account number as a parameter. It creates a search
// string using the account number and retrieves the value of the
// credit_rating field.

String accountNumber = functionParams.get("number");

HashMap data = new HashMap();

String searchStr = "number = '" + accountNumber + "'";
Result result = Functions.searchRecords("ACCOUNT", "credit_rating", searchStr );
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
   Functions.throwError("Account could not be found");
}
else
{
  //Records retrieved successfully
  ParametersIterator iterator = result.getIterator();
  if (iterator.hasNext())
  {
    Parameters params = iterator.next();
    data.put("credit_rating", params.get("credit_rating"));
  }
}

return data;