getRecord
From LongJump Support Wiki
Get a record, with specified fields.
- Syntax
Result result = Functions.getRecord(String objectName, String fields, String recordID {, Parameters params} );
- Parameters
-
- objectName
- An Object Identifier
- fields
- The fields to retrieve.
- A comma-separated list of field names
- The asterisk ("*") wildcard specifies all fields
- (Use the REST API:field Resource to get a complete list of fields.)
- Field lists for database views need to specify the object's alias, as well as the field name.
- 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.
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. }
Example:Access File Data
- When a field points to a file, the PlatformFileBean parameter is used to retrieve the file's contents:
Result result = Functions.getRecord( {objectName}, "fieldName,..." , {record_Id} ); Parameters resultParameters = result.getParameters(); PlatformFileBean file= resultParameters.getPlatformFileBean("fieldName"); String content = file.getEncodedFileContent();
- 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
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 }
- Learn more: Audit Log Fields