AgileApps Support Wiki Pre Release

Difference between revisions of "AddRecord"

From AgileApps Support Wiki
imported>Aeric
imported>Aeric
Line 15: Line 15:
:::<syntaxhighlight lang="java" enclose="div">
:::<syntaxhighlight lang="java" enclose="div">
params.add(PLATFORM.PARAMS.RECORD.DO_NOT_EXEC_DATA_POLICY,"1");
params.add(PLATFORM.PARAMS.RECORD.DO_NOT_EXEC_DATA_POLICY,"1");
</syntaxhighlight>
::* Pass file parameters in the current request to subsequent API calls triggered by a data policy on this object:
:::<syntaxhighlight lang="java" enclose="div">
params.add("PLATFORM.PARAMS.RECORD.ENABLE_MULTIPART","1");
</syntaxhighlight>
</syntaxhighlight>



Revision as of 01:16, 9 September 2011

Add a new record to an object.

Syntax

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

Result result = Functions.addRecord(String objectID, Parameters params); </syntaxhighlight>

Parameters

objectID
The Object to add the record to.
params
  • The field-value pairs for the object you are adding.
  • Data policy override parameter:
<syntaxhighlight lang="java" enclose="div">

params.add(PLATFORM.PARAMS.RECORD.DO_NOT_EXEC_DATA_POLICY,"1"); </syntaxhighlight>

  • Pass file parameters in the current request to subsequent API calls triggered by a data policy on this object:
<syntaxhighlight lang="java" enclose="div">

params.add("PLATFORM.PARAMS.RECORD.ENABLE_MULTIPART","1"); </syntaxhighlight>

Return
Result object

Notepad.png

Note: The Result object contains the record ID for the new record. Use Result.getID to retrieve it.

Example #1: Add a Record to the Account Class

This example creates an instance of Parameters and adds name-value pairs to it. The code then calls addRecord, 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. A

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

Parameters params = Functions.getParametersInstance(); params.add("name", "Acme Solutions"); params.add("number", "GRG2323339"); Result result = Functions.addRecord("ACCOUNT", params); int resultCode = result.getCode(); if(resultCode < 0) {

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

} else {

   // Take other actions on successful addition
   // of the account

} </syntaxhighlight>


Example #2: Add a Record with a Multi Object Lookup field

This example add a record to an object that contains a Multi Object Lookup, where:

  • Books is an object that contains a MultiObject Lookup field
  • libraryBook is a Multi Object Lookup field that points to a particular library and the book it came from
  • e5fadf228160483b81ea8d84c71259c9 is the ID of the Library object that contained the book
  • 767645492 is the record ID of the book in that library
<syntaxhighlight lang="java" enclose="div">

Parameters params = Functions.getParametersInstance(); params.add("title", "A Good Book"); params.add("libraryBook", "e5fadf228160483b81ea8d84c71259c9:767645492");

                                   //  {library_object_id}:{record_id}

Result result = Functions.addRecord("Books", params); int resultCode = result.getCode(); if(resultCode < 0) {

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

} else {

   // Successful add. Take other actions, as needed.

}</syntaxhighlight>