Java API:Support Classes and Objects

Java API:Support Classes and Objects

From AT&T Support Wiki

Java API:Support Classes and Objects (Redirected from Support Classes and Objects)
Jump to: navigation, search

__NUMBEREDHEADINGS__

Support classes and objects used with the Java API:

1. Parameters Class

The Parameters class is a set of key-value pairs that holds a list of fields and their values:

  • You add key-value pairs to a Parameters object to pass values to Java API calls as input parameters. Each Java API call knows how to extract the key-value pairs and use the field values.
  • You extract key-value pairs that the Java API calls return.

You can see the fields defined for an object by selecting Designer > Objects > {object} > Fields.

1.1 Instantiating

You cannot instantiate a Parameters object with the new operator. Instead, you make the getParametersInstance utility call in the Java API:

Parameters p = Functions.getParametersInstance();

You can also get an instance of a Parameters object by calling getParameters in the Result object.

Example

As an example, in the account object, there is a field called name that holds the name of an organization. Follow these steps to set the name field and add a new account record:

  1. Create an instance of the Parameters object
  2. Add the name field to it, setting the value (such as "Acme Solutions")
  3. Pass the Parameters object to the addRecord call

The code for this example is:

Parameters account = Functions.getParametersInstance();
account.add("name", "Acme Solutions");
String accountName = account.get("name");
Result result = Functions.addRecord("ACCOUNT", account);

1.2 Methods

The Parameters object has following methods which you can use to manipulate the set of key-value pairs.

1.2.1 add

Adds a key-value pair to the object.

Signature of the Method

void add(String key, Object value)
Example
This example the creates an instance of Parameters and then adds a key-value pair to it. As is frequently the case, it uses a string for the value, as well as the key.
Parameters params = Functions.getParametersInstance();
params.add("name", "Acme Solutions");

1.2.2 get

Gets the value of the given key.

You must make sure the string is valid. No error is returned if you try to get an invalid string.

Signature of the Method

String get(String key)
Example
This example creates an instance of Parameters, adds a key-value pair to it, and then calls get to assign that value to a variable.
Parameters params = Functions.getParametersInstance();
params.add("name", "Acme Solutions");
String accountName = params.get("name");

1.2.3 getDate

Gets a date value for the given key.

The returned value maps to java.util.Date.

For the first signature, this method throws a Java Exception if a date cannot be formed from the given key's value. For the second signature, this call returns defaultValue if a date cannot be formed.

Method Signature

Date getDate(String key)
Date getDate(String key, Date defaultValue)
Example #1 - Get a Date
Use the getDate() method to retrieve a value in 'Date' format from the Parameters object.

This example assigns the result of a getRecord call to an instance of Parameters and then calls getDate with one parameter to assign the value to a variable.

If the following code is run from a data policy on any object, you can use requestParams to retrieve the record ID of the record and object ID of the object
String recordID = requestParams.get("record_id");
Result result = Functions.getRecord(requestParams.get("object_id"), "record_id,date_created", recordID);
Functions.debug("Record retrieved in function using getRecord:"
  + result.getMessage());
Date d = (result.getParameters()).getDate("date_created");
Example #2 - Get an Existing or Default Date
This example assigns the result of a getRecord call to an instance of Parameters. The code then calls getDate with two parameters to assign the value to a variable; if a date value cannot be formed, the current date is assigned. The following code can be used in scenarios when we want to retrieve date field even if it is not populated. Assigns a default value of current Date.
String recordID = requestParams.get("record_id");
Result result = Functions.getRecord(requestParams.get("object_id"), "record_id,date_created", recordID);
Functions.debug("Record retrieved in function using getRecord:" + result.getMessage());

Parameters params = result.getParameters();
Date accountCreationDate = params.getDate("date_created", new Date());
// If the date_created field is not null or blank, returns
// the date value, otherwise returns the current date.

1.2.4 getBoolean

Gets a Boolean value for a given key. If the value is equal to "1" or "true" or Boolean True, this call returns "true", otherwise it returns "false".

Signature of the Method

boolean getBoolean(String key)
Example
This example assigns the result of a getRecord call to an instance of Parameters. The code then calls getBoolean to assign a property called do_not_call to a variable called do_not_call which is then conditonally tested to determine the code to execute.
// Some code to populate accountID
String accountID = "";
//If the following code is being used on a data policy from Account object,
//you can retrieve the ID of the account record using requestParams
String accountID = requestParams.get("record_id");
Result recordRetrieved = Functions.getRecord(requestParams.get("object_id"), "record_id,date_created,do_not_call", accountID);
Functions.debug("Record retrieved in function using getRecord:" + recordRetrieved.getMessage());
boolean doNotCall = (recordRetrieved.getParameters()).getBoolean("do_not_call");
if(doNotCall)
{
    // Code here will specify what to do when doNotCall is true
}
else
{
    // Code here will specify what to do when
    // doNotCall is false (in other words, when it is OK to call)
}

1.2.5 getInteger

Gets an integer value for the given key.

For the first signature, this method throws a Java Exception if an integer cannot be formed from the given key's value. For the second signature, this call returns defaultValue if an integer cannot be formed.

Signature of the Method

int getInteger(String key)

int getInteger(String key, int defaultValue)
Example
This example assigns the result of a getRecord call to an instance of Parameters and then calls getInteger with one parameter to assign the value to a variable.
String accountID = "";
// Assuming the following code is being called from a policy on Account object
accountID = requestParams.get("record_id");
Result recordRetrieved = Functions.getRecord("ACCOUNT", "record_id,employees", accountID);
Functions.debug("Record retrieved in function using getRecord:" + recordRetrieved.getMessage());
int employees = (recordRetrieved.getParameters()).getInteger("employees");
Example
This example assigns the result of a getRecord call to an instance of Parameters. The code then calls getInteger with two parameters to assign the value to a variable; if an integer value cannot be formed, 10 is assigned.
String accountID = "";
// Assuming the following code is being called from a policy on Account object
accountID = requestParams.get("record_id");
Result recordRetrieved = Functions.getRecord("ACCOUNT", "record_id,employees", accountID);
Functions.debug("Record retrieved in function using getRecord:" + recordRetrieved.getMessage());
int employees = (recordRetrieved.getParameters()).getInteger("employees", 10);
// This will return 10 employees if value of employees
// is null or blank.

1.2.6 getFloat

Gets a float value for the given key.

For the first signature, this method throws a Java exception if a float cannot be formed from the given key's value. For the second signature, this call returns defaultValue if a float cannot be formed.

Signature of the Method

float getFloat(String key)

float getFloat(String key, float defaultValue)
Example
This example assigns the result of a getRecord call to an instance of Parameters and then calls getFloat with one parameter to assign the value to a variable.
String accountID = "";
String objectID = "";
// Let us assume the following code is being used in a data policy related to ACCOUNT
//You can use requestParams object to retrieve the record ID and object ID
accountID = requestParams.get("record_id");
objectID = requestParams.get("object_id");
Result recordRetrieved = Functions.getRecord("ACCOUNT","record_id,revenue,date_created", accountID);
Functions.debug("Result from getRecord!\nMessage:" + recordRetrieved.getMessage() + "\nCode:" + recordRetrieved.getCode());
if(recordRetrieved.getCode() == 1)
{
   // This will return the revenue as 0
   // if the value of employees is null or blank
   Float totalRevenue = (recordRetrieved.getParameters()).getFloat("revenue");
}
Example
The following example show how to assign default values when you try to retrieve a float value using getFloat()

This example assigns the result of a getRecord call to an instance of Parameters. The code then calls getFloat with two parameters to assign the value to a variable; if a float value cannot be formed, 0.0 is assigned.

String accountID = "";
String objectID = "";
// Let us assume the following code is being used in a data policy related to ACCOUNT
//You can use requestParams object to retrieve the record ID and object ID
accountID = requestParams.get("record_id");
objectID = requestParams.get("object_id");
Result recordRetrieved = Functions.getRecord("ACCOUNT","record_id,revenue,date_created", accountID);
Functions.debug("Result from getRecord!\nMessage:" + recordRetrieved.getMessage() + "\nCode:" + recordRetrieved.getCode());
if(recordRetrieved.getCode() == 1)
{
   // This will return the revenue as 0
   // if the value of employees is null or blank
   Float totalRevenue = ((recordRetrieved.getParameters()).getFloat(("revenue"), 0.0f));
}

1.2.7 remove

Removes a key-value pair for the given key.

Signature of the Method

void remove(String key)
Example
This example creates an instance of Parameters, adds a key-value pair to it, and then removes that key-value pair.
Parameters myAccount = Functions.getParametersInstance();
myAccount.add("name", "Acme Solutions");
myAccount.remove("name");

1.2.8 clear

Removes all key-value pairs.

Signature of the Method

void clear()
Example
This example creates an instance of Parameters, adds key-value pairs to it, and then removes all the key-value pairs.
Parameters params = Functions.getParametersInstance();
params.add("name", "Acme Solutions");
params.add("number", "60000");
params.clear();

1.2.9 size

Returns the size of the Parameters object.

Signature of the Method

int size()
Example
This example creates an instance of Parameters and adds two key-value pairs to it. The code then assigns the result of calling size to a variable called sizeOfParameters; at this point sizeOfParameters contains 2. Next, the code calls remove to delete one of the name-value pairs and assigns the result of calling size to sizeOfParameters; at this point sizeOfParameters contains 1.
Parameters myAccount = Functions.getParametersInstance();
myAccount.add("name", "Acme Solutions");
myAccount.add("number", "Acme Solutions");
int sizeOfParameters = myAccount.size();
// sizeOfParameters variable is now 2

myAccount.remove("name");
sizeOfParameters = myAccount.size();
// sizeOfParameters variable is now 1

1.2.10 getObject

Returns an Object of the value for the given string. Used to retrieve the record being imported as a string array.

Signature of the Method

Object getObject(String key)
Example
//Retrieve the row that will be imported
//The String array returned will contain all the values in the row as its various elements
String[] accountArray = (String[])requestParams.getObject("record");
//Retrieve the element
String name = accountArray[0];
//Check the value of the column
//Add the check based on your criteria
if (name.equals("Acme"))
{
   //Use throwError API so as to report the error
   //The record that did not meet the criteria
   //Will not be imported  
    String msg = "Ignoring record:" + name;
    Functions.debug(msg);       // Log it
    Functions.throwError(msg);  // Dialog it
}
else
{
   //Add you custom code here to proceed further
   Functions.debug("Value of record in csv:" + name);
}


2. ParametersIterator Class

The ParametersIterator class holds a list of Parameters objects returned by the searchRecords call. You can iterate through an instance of ParametersIterator to process Parameters objects one-by-one.

You create an instance of a ParametersIterator by making a getIterator call in the Result object.

2.1 Methods

The ParametersInterator class has following methods which you can call to manipulate the Parameters object:

2.1.1 hasNext

Returns true if there are more objects in the list, otherwise returns false. This method is used to iterate through a ParametersIterator object to get Parameters objects one-by-one.

Signature of the Method

boolean hasNext()

2.1.2 next

Gets the next Parameters object.

Signature of the Method

Parameters next()

2.1.3 remove

Removes the current Parameters object from the ParametersIterator object. Normally you do not need to call this.

Signature of the Method

void remove()

ParametersIterator Class Example

This example performs a search and if the search was successful and returned records, the code creates an instance of ParametersIterator. In a while loop, the code calls the ParametersIterator.next method to get an instance of Parameters from which it then extracts the name and number keys.

String accountID = "";
// Some logic to populate accountID variable
Result result = Functions.searchRecords("ACCOUNT", "record_id,name,number",
    "name contains 'Acme'");
int resultCode = result.getCode();
if(resultCode < 0)
{
    // Some error happened.
    String msg = "Account could not be retrieved";
    Functions.debug(msg + ":\n" + result.getMessage());  // Log details
    Functions.throwError(msg + ".");                     // Error dialog
}
else if(resultCode == 0)
{
  // No records found. Take action according to your business logic
}
else
{
   //Records retrieved successfully
   ParametersIterator iterator = result.getIterator();
   while(iterator.hasNext())
   {
     Parameters myAccount = iterator.next();
     String accountID = myAccount.get("record_id");
     String accountName = myAccount.get("name");
     String number = myAccount.get("number");
     // Take action according to your business logic
   }
}


3. Result Class

An instance of the Result class is returned by many of the Java APIs.

Contents

Considerations
  • If the return code is less than zero, it is an error code.
The Result object contains an error message that explains the error.
  • If the return code is zero, the call succeeded, but no records are present.
This value is returned by an add, update, or delete, or when no records match specified search criteria.
  • If the return code is greater than zero, the value is the number of records in the result set.
In that case, there are two options:
  • If the API expected to return a single record, as in a getRecord operation, the getParameters method (below) returns a Parameters object that contains the record fields.
  • If the API expected to return multiple records, as in an execSQL query or a searchRecords operation, then the getIterator method (below) is used to cycle through the list of Parameters objects contained in the Result set (one per record). (In that case, the getParameters method returns null.)

3.1 Methods

The Result class has following methods.

3.1.1 getCode

Gets the error code for record handling calls such as addRecord, updateRecord, deleteRecord, and so on.

For the searchRecords and getRecord calls, the code indicates the number of records returned.

These are the rules that the record handling calls follow for setting the error code:

  • All record handling calls set the error code to negative one (-1) if not successful.
  • Most record handling calls set the error code to zero (0) if successful. The exceptions to this rule are:
    • getRecord sets the error code to one (1) if successful
    • searchRecord sets the error code to the number of records retrieved if successful

Signature of the Method

int getCode()
Example
This example 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.
Parameters myAccount = Functions.getParametersInstance();
myAccount.add("name", "Acme Solutions");
Result result = Functions.addRecord("ACCOUNT", params);
int returnCode = result.getCode();
if(returnCode < 0)
{
    String msg = "Account could not be added";
    Functions.debug(msg + ":\n" + result.getMessage());  // Log details
    Functions.throwError(msg + ".");                     // Error dialog
}
else
{
  // take other actions according to
  // your business logic.
}

3.1.2 getID

Gets the record identifier set by addRecord and generateDocument. When these calls fail, the record identifier is an empty string.

Signature of the Method

String getID()
Example
This example 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 successful, the code calls getID to extract the record identifier.
Parameters myAccount = Functions.getParametersInstance();
myAccount.add("name", "Acme Solutions");
Result result = Functions.addRecord("ACCOUNT", myAccount);
int returnCode = result.getCode();
if(returnCode < 0)
{
    String msg = "Account could not be added";
    Functions.debug(msg + ":\n" + result.getMessage());  // Log details
    Functions.throwError(msg + ".");                     // Error dialog
}
else
{
  String id = result.getID();
  // use the ID to addTask, addActivity or
  // add any other related object.
}

3.1.3 getMessage

Gets the message that indicates success or failure.

Signature of the Method

String getMessage()
Example
This example 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 getMessage to extract the message string.
Parameters myAccount = Functions.getParametersInstance();
myAccount.add("name", "Acme Solutions");
Result result = Functions.addRecord("ACCOUNT", params);
int returnCode = result.getCode();
if(returnCode < 0)
{
    String msg = "Error adding Acme Solutions account";
    Functions.debug(msg + ":\n" + result.getMessage());  // Log details
    Functions.throwError(msg + ".");                     // Error dialog
}
else
{
  String id = result.getID();
  // use the ID to addTask, addActivity or
  // add any other related object.
}

3.1.4 getIterator

Gets a ParametersIterator object after a searchRecords call.

Signature of the Method

ParametersIterator getIterator()
Example
This example calls searchRecords, 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 successful and records were returned, the code creates an instance of ParametersIterator. In a while loop, the code calls the ParametersIterator.next method to get an instance of Parameters from which it then extracts the record identifier.
Result result = Functions.searchRecords("ACCOUNT", "record_id,name, number,city", "name starts with 'Acme'");
int returnCode = result.getCode();
if(returnCode < 0)
{
    String msg = "Error searching Account records";
    Functions.debug(msg + ":\n" + result.getMessage());  // Log details
    Functions.throwError(msg + ".");                     // Error dialog
}
else if(returnCode == 0)
{
  Functions.throwError("No records found");
}
else
{
  ParametersIterator iterator = result.getIterator();
  while(iterator.hasNext())
  {
    Parameters myAccount = iterator.next();
    String id = myAccount.get("record_id");
    // execute your other business logic
  }
}

3.1.5 getParameters

Creates a Parameters object.

Signature of the Method

Parameters getParameters()
Example
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 successful and records were returned, the code creates an instance of Parameters and extracts the name.
String accountID = "";
// Some code to populate accountID variable
Result result = Functions.getRecord("ACCOUNT", accountID);
int returnCode = result.getCode();
if(returnCode < 0)
{
    String msg = "Error retrieving Account record";
    Functions.debug(msg + ":\n" + result.getMessage());  // Log details
    Functions.throwError(msg + ".");                     // Error dialog
}
else
{
  Parameters params = result.getParameters();
  String accountName = params.get("name");
  // execute your other business logic based on name
}


4. HttpConnection Class

The HttpConnection class makes a HTTP connection to a given URI. You can use it to make GET and POST requests to other web services.

HTTPS calls are supported only for URIs that have standard security certificates.

When you call the execute method in HttpConnection, it executes the request, gets the response, and closes the connection. This means that a single object cannot be used multiple times. For multiple HTTP requests, instantiate multiple instances.

Note: Make sure that the URL is properly encoded when instantiating an HttpConnection object.

4.1 Constructor

You create an instance of HttpConnection using the new operator.

Method signature
HttpConnection con = new HttpConnection(int methodType, String URI)
methodType
Sets the HTTP method type:
  • CONSTANTS.HTTP.METHOD.GET for HTTP GET requests
  • CONSTANTS.HTTP.METHOD.POST for HTTP POST requests
String URI
URI to which to connect

4.2 Methods

The methods are:

4.2.1 addHeader

Adds a key-value pair to the request header.

Method signature
void addHeader(String key, String value)
Parameters
  • key - The name of the key
  • value - The value of the key
Return
None

4.2.2 addParameter

Adds a parameter to an HTTP POST request. This methods throws an exception if it is called for an HTTP GET request.

Method signature
void addParameter(String key, String value)
Parameters
  • key - The name of the key
  • value - The value of the key
Return
None

4.2.3 execute

Executes the request and returns a standard HTTP response such as "200 - OK" or "404 - not found".

Method signature
int execute()
Parameters
None
Return
Standard HTTP response

4.2.4 getResponse

Returns the response as a String.

Method signature
String getResponse()
Parameters
None
Return
The response from the service

4.2.5 encode

Returns a String encoded from s.

Method signature
String encode(String s)
Parameters
  • s - The string to encode
Return
The encoded string

4.2.6 getResponseHeaders

Retrieve the headers from the HTTP Response from an external server. It is a map of String Header Name/Header Value pairs.

For example, if the Header Content-Length is equal to 10008, then "Content-Length" is the Header Name and "10008" is the Header Value.

This method is to be called after execute method of HttpConnection.

Method signature
HashMap<String name, String value> getResponseHeaders()
Parameters
None
Return
A HashMap of Header Name/Header Value string pairs

4.2.7 setRequestBody

Specify the body of the request, the content type, and character set.

Method signature
HashMap<String name, String value> getResponseHeaders()
Parameters
  • content-Type - String. One of the valid MIME types for the body of a request. For example: "application/xml".
  • charSet - String. The character set used in the request. For example: "utf-8".
Return
None
Learn more:

4.3 HttpConnection Example

This example gets the result of a Google search for "IT Leaders".

HttpConnection con = new HttpConnection(CONSTANTS.HTTP.METHOD.GET,
    "http://www.google.com/search?hl=en&q=IT+Leaders&btnG=Google+Search");
int code= con.execute();
String response = con.getResponse();

File:notepad.png

Note: The typical response format is JSON. Those libraries are built into the platform. The APIs are documented at JSON.org.


5. SearchContext Class

This class is designed for large, complex queries. Using it, you can formulate a search query one part at a time, and have each part validated independently, rather than putting the entire query in one long string and having it validated all at once.

5.1 Creating a SearchContext Object

Use the setters and getters in the SearchContext class to set up the query. (The syntax for each part is identical to that used with the REST APIs to create a Dynamic Search. The only difference is that you don't have to concatenate them all into a single string.)

5.2 Using the SearchContext Object

These APIs take a SearchContext object:

  • Functions.searchRecords(SearchContext searchContext)
  • Functions.searchGlobalPicklists(SearchContext searchContext)
  • Functions.searchPackages(SearchContext searchContext)
  • Functions.searchSocialFeeds(SearchContext searchContext)
  • Functions.searchSocialGroups(SearchContext searchContext)

Learn more: Uses recorded in the Javadocs

5.2.1 Example

SearchContext searchContext = new SearchContext();

searchContext.setFieldList("*");
searchContext.setObjectId("");    // For a record search: objectName or ID
searchContext.setPage(0);
searchContext.setPageSize(5000);
searchContext.setFilter("title contains 'Order' ");  // Criteria
searchContext.setSortBy("date_created");
searchContext.setSortBy2("title");
searchContext.setSortOrder("DESC");
searchContext.setSortOrder2("ASC");

List<GlobalPicklistBean> results;
results = Functions.searchGlobalPicklists(searchContext);


6. request Object in JSP Pages

The request object is available in any JSP Page. It contains information provided when the HTTP request is made. The information it contains can be used with the REST record Resource or Java Record Handling APIs to get further information from the record.

When a JSP page is invoked by an active record, the request object contains record identifiers.

Record-identifying information is available when:

To get all of the parameters available in the request object, and their values:

<%
  String[] params = request.getParameterValues();
  for (int i=0; i<params.length; i++)
  {
    String paramName = params[i];
    String paramValue = request.getParameter( paramName );
  }
%>

To obtain a record identifier from a request object sent by the platform:

With the object ID and record ID, use the getRecord API to retrieve the record.
<%
  String object_id = request.getParameter("object_id");
  String record_id = request.getParameter("record_id");
%>

File:notepad.png

Note: Although the object_id is alphanumeric, it can be used in any API that requires an object name.

To obtain a record identifier from a request object sent by a Custom Action button:

A Custom Action button can be applied to one record, or it can be applied to several records at one time if the user took advantage of the More Actions feature in the record list view.
This code gets the record IDs and uses the searchRecords API to retrieve the records:
<%
  // Get the object ID and the comma separated list of record IDs
  String object_id = request.getParameter("object_id");
  String selectedRecords = request.getParameter("selectedRecords");

  // Break the comma-separated list into record IDs.
  // Join them with "OR" operands for use when searching for the records
  String filterCriteria = "";
  if (selectedRecords != null)
  {
    StringTokenizer st = new StringTokenizer(selectedRecords,",");
    while (st.hasMoreTokens())
    {
      if ( !"".equals(filterCriteria.trim()))
      {
         // Criteria string isn't empty, and we're adding another expression
         // Prefix the new expression with a boolean OR operator
         filterCriteria += " OR "
      }
      filterCriteria += "record_id = "+ st.nextToken();
    }
  }

  // Use the filter criteria to fetch the selected records
  // Here, we ask for the record_id and name fields
  Result results;
  results = Functions.searchRecords(object_id , "record_id,name", filterCriteria);
  int resultCode = results.getCode();
  if (resultCode < 0)
  {
     // Error occurred
  }
  else if (resultCode == 0)
  {
    // No records found. (This situation should never occur.)
  }
  else
  {
    // Records retrieved successfully
    // Process them here
    ParametersIterator iterator = results.getIterator();
    while(iterator.hasNext())
    {
      Parameters params = iterator.next();
      String recordID = params.get("record_id");
      String recordName = params.get("name");
      // Take additional action according to your business logic
    }
  }
%>

7. requestParams Object in Data Policies

The requestParams object is available when Executing Java Code in a Data Policy. It contains name/value pairs for the fields in the current record. It is an instance of the Parameters Class.

File:notepad.png

Note: You can see the fields defined for an object by selecting
Designer > Objects > {object} > Fields.

Example
This example creates a task to make a call to a new account using the name field in the current object.
String accountId = requestParams.get("id");
String accountName = requestParams.get("name");
Parameters params = Functions.getParametersInstance();
params.add("reference_id", "ACCOUNT");
params.add("reference_type", accountId);
params.add("action_type", "Outbound Call");
params.add("status", "Not Started");
params.add("priority", "Normal");
params.add("description", "Call Account " + accountName + ".
Welcome to Acme Solutions,
introduction to our services and (optional) demo"
);

Functions.addTask("Welcome call to Account " + accountName, "03/12/2011",
getEnv(ENV.USER.ID), params);


8. getPriorParams Method in Data Policies

When Writing Java Code for a Data Policy, use the getPriorParams() method in the Parameters object to access field values.

Considerations
  • getPriorParams() returns an instance of the Parameters Class.
  • When a record is updated, it contains the earlier set of values saved in the DB for this record.
  • If a record is updated with no changes to the fields, the prior parameters contains the unchanged values of the fields.
  • When a record is added, the prior parameters of the record are empty.
  • When retrieving values, you'll typically use the get-methods from the Parameters class that let you specify a default value, in case the record value is null.
Retrieving prior values of account name and status
Parameters preParams = requestParams.getPriorParams();
String accountName = preParams .get("name");
Functions.debug("Previous Account Name: " + accountName);
Functions.debug("Earlier value for acccount status: " + preParams.get("account_status"));
Retrieving a field of type Float
To retrieve a field of type 'Currency' without having to type-cast the return value, use getFloat().
Use getFloat(String, float) to handle null values.
Float prior_transaction_amount = preParams.getFloat("amount", 0.0f);
Functions.debug("Prior transaction amount: " + prior_transaction_amount);
Retrieving an integer value
To retrieve a field of type 'Number' without having to type-cast the return value, use getInteger().
Use getInteger(String, int) to handle null values.
int account_num = preParams.getInteger("number", 0);
Functions.debug("Prior account number value: " + account_num);
Retrieving a String value
String account_name = preParams.get("field_name");
Functions.debug("Prior Account name: " + account_name);
Retrieving a text area
String description = preParams.get("description");
Functions.debug("Prior Account description: " + description);
Retrieving a field of type Date
To retrieve a field of type 'Date' without having to type-cast the return value, use getDate().
Date date = preParams.getDate("date_created");
Functions.debug("Prior Account created date: " + date);
Retrieving a field of type Boolean
To retrieve a field of type 'CheckBox' without having to type-cast the return value, use getBoolean().
boolean contract_bool = preParams.getBoolean("contract");
Functions.debug("Prior Account contract: " + contract_bool );


9. tenantContext Object

The tenantContext object is used to access and manage data that has been shared by another tenant, using Tenant Data Sharing Policies.

Once a data sharing policy has been set up, you specify the sharing tenant's ID to get a tenantContext. You then use that object as a parameter in one of the Java APIs for Tenant Data Sharing.

Learn more: TenantContext javadocs

Syntax
try
{
    TenantContext tenantContext = new TenantContext(String tenantId);
}
catch Exception(e)
{
    // An exception is thrown if the specified tenant has not defined
    // a tenant data sharing policy that gives you access.
}
Personal tools