AgileApps Support Wiki Pre Release

getRecord

From AgileApps Support Wiki
Revision as of 01:38, 8 February 2012 by imported>Aeric

Get a record, with specified fields.

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

Result result = Functions.getRecord(String objectName, String fields, String recordID

                 {, Parameters params} );

</syntaxhighlight>

Parameters
objectName
An Object Identifier
fields
The fields to retrieve.
  • A comma-separated list of field names (Use the REST API:field Resource to get a complete list of fields.)
  • The asterisk ("*") wildcard specifies all fields.
  • For related-record fields in a Composite Object, specify the alias of the related object and the field name, where the alias is defined in the Object Relationships:
alias[.alias...].* or alias[.alias...].field
When fetched, an alias becomes a virtual "field" that contains an array of records from the related object, where each record contains the specified field(s).
recordID
A Record Id.
params
An optional com.platform.api.Parameters object. Use it to specify the Retrieve Record Permissions Parameter, in order to find out if the user has update or delete permissions on the record.
Return
Result object. If the return code is greater than zero, use the getParameters() method to get a Parameters object with the record's fields.
Deprecated Field
  • workflow_owner - It is still present and can be used for updates, but it no longer contains any data when returned. Use this resource, instead: getWFOwners.

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";
   Logger.info(msg + ":\n" + result.getMessage(), "Get Key"); // Log details
   Functions.throwError(msg + ".");                           // Error message

} 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: 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";
   Logger.info(msg + ":\n" + result.getMessage(), "Audit"); // Log details
   Functions.throwError(msg + ".");                         // Error message

} 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: Audit Log Fields