AgileApps Support Wiki Pre Release

Difference between revisions of "Using the request Object"

From AgileApps Support Wiki
imported>Aeric
imported>Aeric
 
(14 intermediate revisions by the same user not shown)
Line 12: Line 12:


'''To obtain a record identifier from a <tt>request</tt> object sent by the platform:'''
'''To obtain a record identifier from a <tt>request</tt> object sent by the platform:'''
:With the object ID and record ID, use the [[Java_API:Record_Handling#getRecord|getRecord]] API to retrieve the record.
:<syntaxhighlight lang="java" enclose="div">
:<syntaxhighlight lang="java" enclose="div">
<%
<%
Line 22: Line 23:


'''To obtain a record identifier from a <tt>request</tt> object sent by a Custom Action button:'''
'''To obtain a record identifier from a <tt>request</tt> object sent by a Custom Action button:'''
A [[Custom Action]] button can be applied to one record, or to several records at one time, if the user took advantage of the [[More Actions]] feature in the record list view. Because it can be applied to more than one record at a time, the process for obtaining record IDs differs somewhat.


Here is the code that does the job:
:This code gets the record IDs and uses the [[searchRecords]] API to retrieve the records:
:<syntaxhighlight lang="java" enclose="div">
:<syntaxhighlight lang="java" enclose="div">
<%
<%
    String object_id = request.getParameter("object_id");
  // Get the object ID and the comma separated list of record IDs
    String selectedRecords = request.getParameter("selectedRecords");  
  String object_id = request.getParameter("object_id");
String filterCriteria = "";
  String selectedRecords = request.getParameter("selectedRecords");  
if (selectedRecords != null)
 
{
  // Break the comma-separated list into record IDs.
StringTokenizer st = new StringTokenizer(selectedRecords,",");
  // Join them with "OR" operands for use when searching for the records
while (st.hasMoreTokens())
  String filterCriteria = "";
{
  if (selectedRecords != null)
if ( !"".equals(filterCriteria.trim()))
  {
{
    StringTokenizer st = new StringTokenizer(selectedRecords,",");
filterCriteria = " OR "
    while (st.hasMoreTokens())
}
    {
filterCriteria += "record_id = "+ st.nextToken();
      if ( !"".equals(filterCriteria.trim()))
}
      {
}
        // Criteria string isn't empty, and we're adding another expression
    Result result;
        // Prefix the new expression with a boolean OR operator
    result = Functions.searchRecords(object_id , "record_id,name", filterCriteria);
        filterCriteria += " OR "
    int resultCode = result.getCode();
      }
if (resultCode < 0)
      filterCriteria += "record_id = "+ st.nextToken();
{
    }
}
  }
else if (resultCode == 0)
 
{
  // Use the filter criteria to fetch the selected records
// No records found. Take action according to your business logic
  // Here, we ask for the record_id and name fields
}
  Result results;
else
  results = Functions.searchRecords(object_id , "record_id,name", filterCriteria);
{
  int resultCode = results.getCode();
//Records retrieved successfully
  if (resultCode < 0)
ParametersIterator iterator = result.getIterator();
  {
while(iterator.hasNext())
    // Error occurred
{
  }
Parameters params = iterator.next();
  else if (resultCode == 0)
String recordID = params.get("record_id");
  {
String recordName = params.get("name");
    // No records found. (This situation should never occur.)
// Take action according to your business logic
  }
}
  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
    }
  }
%>
%>
</syntaxhighlight>
</syntaxhighlight>

Latest revision as of 02:02, 14 August 2013

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

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

<%

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

%> </syntaxhighlight>

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.
<syntaxhighlight lang="java" enclose="div">

<%

 String object_id = request.getParameter("object_id");
 String record_id = request.getParameter("record_id");

%> </syntaxhighlight>

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:

This code gets the record IDs and uses the searchRecords API to retrieve the records:
<syntaxhighlight lang="java" enclose="div">

<%

 // 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
   }
 }

%> </syntaxhighlight>