Adding a Smart Browser and process to Perform a Special Task

Submitted by Mike McKay on Wed, 11/09/2016 - 06:23

When customizing the ADempiere application there is often the need to create special forms that can perform specific tasks.  In ADempiere, one way of creating these forms is to use the Smart Browser which can be configured to display a filtered list of information, otherwise known as a "View", allow selections from that list and then to run a Process on the selected items.

In the Flight Training Unit application, an example of that is the batch cancellation of flights so that no customer orders are created for those entries.  If the flights are not cancelled and have no training activity, the logic assumes these are no-shows and charges the customer/student accordingly.  When there is bad weather, an entire day can be lost, with hundreds of flights being cancelled.  To avoid charging all the customers for no-show fees on such a day, the Dispatch staff need a way to cancel a number of flights easily.  This can be done through the Smart Browser.  This article will walk through the creation of the Smart Browser for this particular task.

To start, we create a "View" of the Flight Sheet that includes the columns necessary.  Log in as System/System Administrator. Open the Application Dictionary->View window.  Create the View header as follows:

  • Search Key: FTU_Flightsheet
  • Name: Flightsheet View
  • Description: A view of the records of the flight sheet
  • Comment/Help: Lists all flight activity over a range of days.

Save the record and move to the View Definition Tab.  Here we define the tables that will be part of the View, creating the "FROM" clause of the sql.  In this case, we only have the single FTU_Flightsheet table and no join clauses.  The fields are set as follows:

  • Sequence: 10
  • Table: FTU_Flightsheet_Flight
  • DB Table Alias: fs

Save the record and then click the "Create Columns" button.  This will add the table columns to the View Columns tab.  The columns will have the following information:

  • The standard Name, Description and Comment/Help fields
  • Column: The column name from the table  e.g FTU_Flightsheet_ID_Flight
  • Column SQL: The select clause used for that column e.g. fs.FTU_Flightsheet_ID
  • DB Column Name: The alias given to the selected column e.g. FS_FTU_Flightsheet_ID

The columns are not sorted or filtered in the View window.  It is simply the collection of columns to use to create a list of results based on a number of tables.  The "WHERE" clause and "ORDER BY" clauses of the SQL statement will be generated based on how the view is used.

Next we need to define the process that we will use to cancel the selected flights.  In the Report & Process window, create a new record and fill in the fields as follows:

  • Search Key: FTU_BatchCancelFlights
  • Name: Batch Cancel Flights
  • Data Access Level: Client+Organization
  • Classname: com.mckayerp.ftu.BatchCancelFlights

You can add description and comments as required. 

No parameter definitions required for the process as we are going to rely on the list of selected items from the Smart Browser which will be passed automatically to the process.

On the main "Report & Process" page, click the button to "Generate Class from Process". Point the directory dialog at the location in your repository where you want the class generated and click confirm.  If you refresh the repository in your IDE, the new class should appear.  It will have a main class and an abstract version of the class.  The abstract class will contain the static definitions of the name of the parameters and functions to load these parameters along with a few other helpful utility functions.  This is a great way to create the skeleton of the process code.

Now we can create the Smart Browse and test the process skeleton before we add the code details.  Open the Smart Browse window and define the Smart Browse for the View and Process just created.  As there will potentially be a lot of data in the Flightsheet table, deselect the "Is executed query by default" button to prevent all flights from being loaded with the Smart Browse form is opened.  Leave the Sql Where field empty for now and save the record.

Click on "Create Fields" to generate the list of fields the Browser will display.

Add fields to the Browse Field using the Browse Field Sequence tab.  Ensure that the first field is the ID field for the View to select the records. In this case that is FS_FTU_Flightsheet_ID.  Also ensure the field uses the reference "ID" so that it appears as a check box in the Smart Browser.

Select the fields that will be used to filter the list and set the display order.

In the Browse Field tab, refresh the data and then edit the fields as required.  On the fields that will also be criteria, also set the mandatory and range as required.  In this example, the Flight Date will be mandatory range and the Business Partner, Instructor and Aircraft will be other non-mandatory criteria.

Add the Smart Browse to the system menu and run the Role Access Update to ensure the user accounts will see it.

Log in as the user and find the new Smart Browser entry. Open the Browser and search for a set of flights that need to be cancelled.  Select multiple lines and click Confirm.  The process will be called with the set of selected keys which can be retrieved by adding/modifying the following lines to the BatchCancelFlightAbstract class:

    /** List of flights to cancel */
    List<Integer> flights;
    

    @Override
    protected void prepare()
    {
        flights = this.getSelectionKeys();
    }


The BatchCancelFlights class can then access the flights list variable and make the necessary changes to the flights.