AgileApps Support Wiki Pre Release

updateRecord

From AgileApps Support Wiki


Syntax
Result result = Functions.updateRecord(String objectName, String recordID, Parameters params);

Parameters

objectName
The identifier of the object
recordID
The identifier of the record to update.
  • Use the searchRecords API to retrieve the record ID
  • An error is returned if the record is not found.
params
  • The field-value pairs for the object.
  • Turn off rules that might otherwise be triggered as a result of this action:
params.add(PLATFORM.PARAMS.RECORD.DO_NOT_EXEC_RULES,"1");
  • Pass file parameters in the current request to any subsequent API calls made in a data policy defined on this object:
params.add(PLATFORM.PARAMS.RECORD.ENABLE_MULTIPART,"1");

Return

Result object

Example #1: Update an Account Record

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

Parameters params = Functions.getParametersInstance();
String accountID = "";
// Some logic to populate accountID variable.
params.add("name", "Acme Solutions");
params.add("number", "GRG2323339");
Result result = Functions.updateRecord("ACCOUNT", accountID, params);
int resultCode = result.getCode();
if(resultCode < 0)
{
    // Some error happened.
    String msg = "Account could not be updated";
    Logger.info(msg + ":\n" + result.getMessage(), "Accounts"); // Log details
    Functions.throwError(msg + ".");                            // Error message
}
else 
{
    // Take other actions after successful addition of the account.
}

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

This example uses the same fields and record IDs as those shown when adding a record with a multiobject lookup field.

Parameters params = Functions.getParametersInstance();
String bookID = "117645552"
params.add("title", "Another Good Book"); 
params.add("libraryBook", "9978946545:767645492");
                      //  {object_id}:{record_id}
Result result = Functions.updateRecord("Books", bookID, params); 
int resultCode = result.getCode();
if(resultCode < 0)
{
    // Some error happened.
    String msg = "Book record could not be updated";
    Logger.info(msg + ":\n" + result.getMessage(), "Library"); // Log details
    Functions.throwError(msg + ".");                           // Error message
}
else
{
    // Successful update. Take other actions, as needed.
}