Difference between revisions of "GetRecord Examples"
imported>Aeric |
imported>Aeric m (Text replace - '// Error dialog' to '// Error message') |
||
(5 intermediate revisions by the same user not shown) | |||
Line 12: | Line 12: | ||
// Some error happened. | // Some error happened. | ||
String msg = "Account could not be retrieved"; | String msg = "Account could not be retrieved"; | ||
Logger.info(msg + ":\n" + result.getMessage(), "Get Key"); // Log details | |||
Functions.throwError(msg + "."); | Functions.throwError(msg + "."); // Error message | ||
} | } | ||
else | else | ||
Line 33: | Line 33: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
:''Learn more:'' See the [{{DOCHOST}}/javadocs/com/ | :''Learn more:'' See the [{{DOCHOST}}/javadocs/com/platform/beans/PlatformFileBean.html PlatformFileBean] javadocs for a complete list of methods. | ||
====Example: Access an Audit Log==== | ====Example: Access an Audit Log==== | ||
:[[Audit Log]]s can be searched using the <tt>getRecord</tt> and <tt>searchRecord</tt> APIs | :[[Audit Log]]s can be searched using the <tt>getRecord</tt> and <tt>searchRecord</tt> APIs | ||
::''Learn more: [[ | ::''Learn more: [[Audit Log Fields]] | ||
:;How it Works: | :;How it Works: | ||
Line 64: | Line 64: | ||
// Some error happened. | // Some error happened. | ||
String msg = "Log could not be retrieved"; | String msg = "Log could not be retrieved"; | ||
Logger.info(msg + ":\n" + result.getMessage(), "Audit"); // Log details | |||
Functions.throwError(msg + "."); | Functions.throwError(msg + "."); // Error message | ||
} | } | ||
else | else | ||
Line 82: | Line 82: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
:''Learn more: [[ | :''Learn more: [[Audit Log Fields]]'' |
Latest revision as of 22:30, 10 September 2013
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