AgileApps Support Wiki Pre Release

Difference between revisions of "Using the request Object"

From AgileApps Support Wiki
imported>Aeric
imported>Aeric
Line 28: Line 28:
:<syntaxhighlight lang="java" enclose="div">
:<syntaxhighlight lang="java" enclose="div">
<%
<%
    String object_id = request.getParameter("object_id");
  String object_id = request.getParameter("object_id");
    String selectedRecords = request.getParameter("selectedRecords");  
  String selectedRecords = request.getParameter("selectedRecords");  
    String filterCriteria = "";
  String filterCriteria = "";
    if (selectedRecords != null)
  if (selectedRecords != null)
  {
    StringTokenizer st = new StringTokenizer(selectedRecords,",");
    while (st.hasMoreTokens())
     {
     {
        StringTokenizer st = new StringTokenizer(selectedRecords,",");
      if ( !"".equals(filterCriteria.trim()))
        while (st.hasMoreTokens())
      {
        {
        filterCriteria = " OR "
            if ( !"".equals(filterCriteria.trim()))
      }
            {
        filterCriteria += "record_id = "+ st.nextToken();
                filterCriteria = " OR "
            }
            filterCriteria += "record_id = "+ st.nextToken();
        }
     }
     }
    Result result;
  }
    result = Functions.searchRecords(object_id , "record_id,name", filterCriteria);
  Result result;
    int resultCode = result.getCode();
  result = Functions.searchRecords(object_id , "record_id,name", filterCriteria);
    if (resultCode < 0)
  int resultCode = result.getCode();
  if (resultCode < 0)
  {
    // Error occurred
  }
  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 params = iterator.next();
      String recordID = params.get("record_id");
      String recordName = params.get("name");
      // Take action according to your business logic
     }
     }
    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 params = iterator.next();
            String recordID = params.get("record_id");
            String recordName = params.get("name");
            // Take action according to your business logic
        }
    }
%>
%>
</syntaxhighlight>
</syntaxhighlight>

Revision as of 20:06, 11 January 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:

<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:

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:

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

<%

 String object_id = request.getParameter("object_id");
 String selectedRecords = request.getParameter("selectedRecords"); 
 String filterCriteria = "";
 if (selectedRecords != null)
 {
   StringTokenizer st = new StringTokenizer(selectedRecords,",");
   while (st.hasMoreTokens())
   {
     if ( !"".equals(filterCriteria.trim()))
     {
       filterCriteria = " OR "
     }
       filterCriteria += "record_id = "+ st.nextToken();
   }
 }
 Result result;
 result = Functions.searchRecords(object_id , "record_id,name", filterCriteria);
 int resultCode = result.getCode();
 if (resultCode < 0)
 {
    // Error occurred
 }
 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 params = iterator.next();
     String recordID = params.get("record_id");
     String recordName = params.get("name");
     // Take action according to your business logic
   }
 }

%> </syntaxhighlight>