getRecord Examples

From AgileApps Support Wiki
Revision as of 18:39, 30 September 2011 by imported>Aeric (→‎Example:Access File Data)

Example: Retrieve a Key

This example calls getRecord, assigning the returned value to an instance of Result and calling Result.getCode to assign the error code to a variable which is then conditionally checked to determine the code to execute. If the call was not successful, the code calls throwError to display an error dialog. If the call was successful, the code creates an instance of Parameters from which it then extracts the city key.

<syntaxhighlight lang="java" enclose="div">

String accountID = ""; // Some logic to populate accountID variable. Result result = Functions.getRecord("ACCOUNT","city,country",accountID); int resultCode = result.getCode(); if(resultCode != 1) {

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

} else {

 //Records retrieved successfully
 Parameters resultParameters = result.getParameters();
 String city = resultParameters.get("city");
 // Other code according to your business logic.

} </syntaxhighlight>

Example:Access File Data

When a field points to a file, the PlatformFileBean parameter is used to retrieve the file's contents:
<syntaxhighlight lang="java" enclose="div">

Result result = Functions.getRecord( {objectName}, "fieldName,..." , {record_Id} ); Parameters resultParameters = result.getParameters(); PlatformFileBean file= resultParameters.getPlatformFileBean("fieldName"); String content = file.getEncodedFileContent(); </syntaxhighlight>

Learn more: See the PlatformFileBean javadocs for a complete list of methods.

Example: Access an Audit Log

Audit Logs can be searched using the getRecord and searchRecord APIs
Learn more: Reference documentation for Audit Log fields
How it Works
Provide an audit log recordID to get a single record and retrieve a list of audit log fields.
Syntax
public static Result Functions.getRecord(String objectId, String fields, String recordId)
objectId
log
fields
record_id, ownerid, type, operation, object_singular_name, date_created, description, type_code
recordId
audit log record Id
Return
Result object
Audit Log Example Based on recordID
<syntaxhighlight lang="java5" enclose="div">

Result result = Functions.getRecord("log","record_id,type,operation,"+ "object,description","656");

int resultCode = result.getCode();

if(resultCode != 1) {

   // Some error happened.
   String msg = "Log could not be retrieved";
   Functions.debug(msg + ":\n" + result.getMessage());  // Log details
   Functions.throwError(msg + ".");                     // Error dialog

} else {

 //Records retrieved successfully
   Parameters params = result.getParameters();
   String desc= params.get("description");
   String type= params.get("type");
   String obj = params.get("object");
   String record_id = params.get("record_id");
   String operation = params.get("operation");                  
   // Take action according to your business logic
  

} </syntaxhighlight>

Learn more: Reference documentation for Audit Log fields