Import Loader Process For Custom Modules

Hi All,

The import loader process is used to load data into the openbravo windows from input files. Openbravo has provided the options to load product, business partner, etc., Now we have the option of creating import process for our own modules with a simple java file (Refer here). Right now this process reads data from csv file(The Input format is parsed using the file file). This can also be extended to read input from other formats by creating a service file similar to IdlServiceJava. The only catch here is that to try this out you need the Professional Subscription, after all not everything comes free in life…:).  I installed the modules, Initial Data Load and Initial Data Load Extension for Java. I used the sample import process that comes along with initial data load extension module and created a new import process for the window frequency.

Here are the steps which I followed.

1. Creating the Java Process file

 package com.fugoconsulting.xyzz.module.template.erpCommon.ad_process;

import org.openbravo.idl.proc.Parameter;
 import org.openbravo.idl.proc.Validator;
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
 import java.text.ParseException;
 import java.math.BigDecimal;
 import java.util.Date;
 import org.apache.log4j.*;

import org.openbravo.base.exception.OBException;
 import org.openbravo.base.provider.OBProvider;
 import org.openbravo.base.structure.BaseOBObject;
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.erpCommon.utility.Utility;
 import org.openbravo.idl.proc.Value;
 import org.openbravo.module.idljava.proc.IdlServiceJava;
 import com.fugoconsulting.xyzz.module.template.XYZZFrequency;

 * @author Pandeeswari
 public class ImportFrequency extends IdlServiceJava {

private static Logger log=Logger.getLogger(ImportFrequency.class);
 DateFormat df = new SimpleDateFormat("dd-MM-yyyy");

 public String getEntityName() {
 return "Simple Frequency";

 public Parameter[] getParameters() {
 return new Parameter[] {
 new Parameter("Organization", Parameter.STRING),
 new Parameter("SearchKey", Parameter.STRING),
 new Parameter("Name", Parameter.STRING),
 new Parameter("Description", Parameter.STRING),
 new Parameter("Factor", Parameter.STRING),
 new Parameter("Date", Parameter.STRING) };

 protected Object[] validateProcess(Validator validator, String... values) throws Exception {
 validator.checkNotNull(validator.checkString(values[1], 40), "SearchKey");
 validator.checkNotNull(validator.checkString(values[2], 60), "Name");
 validator.checkString(values[3], 255);
 return values;

 public BaseOBObject internalProcess(Object... values) throws Exception {

return createFrequency((String) values[0], (String) values[1], (String) values[2],
 (String) values[3], (String) values[4], (String) values[5]);

public BaseOBObject createFrequency(final String Organization, final String searchkey,
 final String name, final String description, final String factor,
 final String aDate)
 throws Exception {

// Frequency
 XYZZFrequency frequencyExist = findDALInstance(false, XYZZFrequency.class, new Value("searchKey", searchkey));
 if (frequencyExist != null) {
 throw new OBException(Utility.messageBD(conn, "XYZZ_FREQ_EXISTS", vars.getLanguage())
 + searchkey);
 XYZZFrequency frequency = OBProvider.getInstance().get(XYZZFrequency.class);

try {
 frequency.setFactor(new BigDecimal(factor));
 // Date date = df.parse(aDate);
 Date  date = new Date();

 } catch (Exception e) {

// End process

return frequency;

I have created the Java File inside modules/mymodule/erpCommon/ad_process. You can place it where ever you want but just be careful to provide the proper Java package name.

Inside the getParameters() method, we provide the columns in the same order as it is in the input file. But the parameter names used in the method need not be the same.

The createFrequency() just inserts the value into the table using OBProvider.  The internalProcess(Object… values) Method which is inherited from IdlServiceJava class is used to call the appropriate method with appropriate parameters.

2. Register the file in entity default value

Register the Entity in Master Data Management -> Initial Data Load  -> Setup  -> Entity Default Value

Make Special note on the class name while adding the entity default value.

3. Import the data using import window

  • Go to Master Data Management -> Initial Data Load -> Process -> Import
  • Choose the input file
  • Choose the entity as Frequency

  • Give Validate
  • Once the input values are validated, the data can be loaded into the actual table by giving process.

  • If there occurs any problem with the input data, it will be logged in the boxes provided in the import screen.

Accessing DOM objects in PeopleSoft pages

I was developing a custom tool  in PeopleSoft where I had to display a widget containing appraisal ratings, compensation details etc., for a particular employee. The widget itself was developed using HTML and Javascript. So I placed an htmlarea in my PeopleSoft page and poured in the widget code. The widget used a level-1 grid as data source.

Sample data in Grid

Appraisal Year Mid-Year Year-End
2007 2 2
2008 1 2
2009 3 2
2010 1 1

Before proceeeding any further, let’s have a peek into DOM. For people who are not familiar with Document Object Model (DOM), it is a cross-platform and language-independent convention for representing and interacting with objects in HTML, XHTML and XML documents. The Document Object Model is a great big hierarchy of objects and functions just waiting to be tickled by JavaScript. To identify the HTML tags behind objects in the PeopleSoft page, I used Firebug (Web Development Tool). Firebug made it simple to find HTML elements buried deep in the page.

Objects in a page can be accessed using:

    1. getElementById – This function is used to get the objects in page based on its id attribute.

For example, an Employee id field on PeopleSoft page might be represented in HTML as

<input id="“XX_APP_EMPLID”" class="PSEDITBOX" type="text" name="“Emplid”" value="“KU0007”" />

The value in “Emplid” field can be accessed by javascript as below. Note that the parameter to getElementById function has to be the value of “id” attribute.

  1. getElementByTagName – This function is used to get the objects in page based on its tag name.
<input id="“XX_APP_EMPLID”" class="PSEDITBOX" type="text" name="“Emplid”" value="“KU0007”" />

getElementByTagName restricts you to access only one HTML element at a time. What if you want to iterate through all “input” tags in the page? getElementsByTagName (note the ‘s’ in Elements) functions allows you to do just that.

Now, how do I access data in a grid in PeopleSoft page?

I knew how to get values from my page fields using getElementById function, however when I tried to use the same function for reading data from my grid:

document.getElementById("GET_ROWS").onclick = function(){

With the code above, I intended to display the value of grid’s first cell (row 1, col 1). The first cell is identified by id “XX_APP_RATING$3”, which I discovered by inspecting the HTML source code using Firebug.

Instead of displaying the value the alert message returned an “undefined” value.

Cracking the Grid

All the data within the grid can be read as array elements in javascript using the getElementsByTagName function. So the onclick function is re-written as:

document.getElementById("GET_ROWS").onclick = function(){
var x = document.getElementById("XX_APP_ RATING$scroll$0").getElementsByTagName("tr");
// Note: Each row in the grid is organized in
tag of the grid object

Now the variable x will contain all the rows from the grid XX_APP_DATA. To access each individual data from the grid rows,

for(var i=0;i     		// Read through each row
                    	var y=x[i].getElementsByTagName("span");
     		// Note: The  tag will contain all the individual cells in the grid

Putting all the pieces together, the complete javascript code to iterate an entire grid is:

document.getElementById("GET_ROWS").onclick = function(){
var x = document.getElementById("XX_APP_ RATING$scroll$0").getElementsByTagName("tr");
  for(var i=0;i // Read through each row
              var y=x[i].getElementsByTagName("span");
// Note: The  tag will contain all the individual cells in the grid
 for(var j=0;j // Read each column in the ith row.
 var td_data = y[j].id;
 var td_data = td_data.replace("XX_APP_ RATING_","");
 var td_data = td_data.substr(0, td_data.indexOf("$"));
 alert(td_data + " = " + y[j].innerHTML);

Database Development Perspective in Eclipse for Openbravo,Postgres

Eclipse IDE is a great tool for Development and specially for development for an ERP like Openbravo. For setting up Openbravo in Eclipse refer here. Also Eclipse Provides many plug ins that could make the development even easier. There are many perspectives provided in Eclipse. (Refer Screen shot below)

Lets see about the Database Development Perspective in this Blog. Database Development Perspective allows us to connect to database directly, export data as files, import data, query, etc…

To connect your Openbravo postgresql database, these are the steps to be performed.

1. Choose Database Development from the available list of perspectives.

2. Create a new Connection and connect the driver to database. Refer the following screen shots.

3. In the Driver definition, choose your host and database name, the database field can be anything (column1), it does not matter. Its just the name that will show in Eclipse.

4. Once this is done, your eclipse will be as below.

Under Schemas, you will have public that will have the tables and functions.

Now you are connected to your database and you can query, or use the other options as I have shown in the screen shot below.

Happy Working..:)