ERP 2.50:Developers Guide/How to add a field to a Window Tab/it
Languages: |
Contents |
Obiettivo
The objective of this how-to is to show how you can add a new field to a tab in Openbravo ERP. This how-to illustrates the required steps for three different types of fields:
- Text field
- Combo-box field
- Reference field
The how-to starts with adding a new text field (contact information) to the Warehouse window. This window can be found at: Warehouse Management > Warehouse and Storage Bin (if you can't find the window in the menu then you probably have to change your role). The subsequent sections will describe the additional actions required for adding reference and combo-box fields.
Aggiungere un Campo Testo a una Scheda
Aggiungere una colonna
The next step is to add a column to the M_Warehouse table so that we have a place to store the data we will be entering in the window.
There is a separate how-to on how-to add a column to an existing table, see the how-to. In this how-to we will give a summary.
The steps to add a column are:
- Create the column in the database.
- Login to the application.
- Go to the table window and do import of columns from database, this will import the new column into the Application Dictionary.
- Correct/add column information.
To create the column in the database you can use any tool you like, your favorite database explorer or command line tools provided by the database server. For this how-to the column has to be added to the M_Warehouse table. Some other points:
- The name of the column must start with EM_ and then the dbprefix of the module (see How to create and package a module for more details), for example EM_HT_Contact_Info.
- The SQL type we select will be varchar(255), this is the standard size for description columns.
- For this how-to this column is nullable, so null is allowed.
In PostgreSQL this column is created with the following SQL:
ALTER TABLE m_warehouse ADD COLUMN em_ht_contact_info varchar(255);
Note: the columnname for the db should be all lowercase
Then login into Openbravo ERP and go to: Application Dictionary > Table and Columns (if you don't see this menu option then your user does not have enough privileges, change to an administrator role). Find the M_Warehouse table and go to the detailed view. Click on the 'Create columns from DB' button.
The system should report back that one column has been created (Created == 1). Click on the Columns link in the top, you should see the em_ht_contact_info column. Click on it to maintain its details. You can see that the correct module has been selected (the dbprefix is used for that).
Some additional remarks about the name field of the column (which is different from the DB Column Name field). The value in the name field is just for two specific functions in Openbravo ERP:
- The generated business object will use this name for the Java member corresponding to this column.
- The REST XML message created for M_Warehouse will use this name as the tagname for the column when it is converted to XML.
Then only set a description and help text. The reference field of the column should already be set correctly to String.
To make sure that the changes do not get lost execute the export.database task. Open a command window/shell and go to the Openbravo ERP development project and then execute the following task:
ant export.database
This will print something like this:
Exporting module: Howto Module Database [name=PostgreSql server; 436 tables; 0 sequences; 58 views; 233 functions; 207 triggers] Path: /home/mtaal/mydata/dev/openbravo/workspaces/obpi/openbravo/modules/org.openbravo.howto/src-db/database/sourcedata Exporting table: AD_Process to module Howto Module Exporting table: AD_Element to module Howto Module Exporting table: AD_Menu to module Howto Module Exporting table: AD_Process_Para to module Howto Module ........ Exporting table: AD_TreeNode to module Howto Module Exporting table: AD_Exceptions to module Howto Module Exporting table: AD_Val_Rule to module Howto Module Exporting table: AD_WF_Node to module Howto Module Exporting table: AD_WF_NodeNext to module Howto Module Exporting table: AD_Form to module Howto Module Exporting table: AD_Window to module Howto Module [exportdatabase] DataSet(1) (name: ADRD) Exporting module: Howto Module Database [name=PostgreSql server; 436 tables; 0 sequences; 58 views; 233 functions; 207 triggers] BUILD SUCCESSFUL Total time: 2 minutes 6 seconds
This will create the relevant directory for the module in the modules directory inside the Openbravo ERP development project. As the screenshot shows, you can see the XML files which correspond to the changes we have been making until now.
Aggiungere un campo alla finestra
The column has been created and it is present in the application dictionary. The next step is to create the field in the window/tab.
However, before we can do that we have to set the core module to be in development. To do that go to: Application Dictionary > Module, double click the core module and check the 'In Development' field and click save. Then go to Warehouse window:
- Go to Application Dictionary > Windows, Tabs and Fields in the application, and search for the Warehouse window (it's name is: Warehouse and Storage Bins).
- Double click the Warehouse window record.
- Then click on the Tab in the top.
- Double click the warehouse tab record.
- Now you are on the Tab view, in the bottom of this view there is a button 'Create Fields'. Click this button.
This will pop-up the following window:
Click Ok, now a new field should have been added to the window/tab. Click on the Field link in the top, you should see the new field in the top of the list. The new field has been added in the top of the form, it is nicer to have it last though. To do this click on Field Sequence and move the new field to the button using the buttons on the right.
The field sequence is set through the sequence field in the detail window of Field.
If you wanted to display the new field in the grid (next to the detailed view) then there is an option at Field level to set this (show in Grid view). Columns in the grid are presented in the same order as fields in edition view.
Ordinare i campi nella griglia
From 2.50MP14, it is possible to sort grid columns in a different manner than fields in edition mode, for this purpose Grid Position field is used. In case all the fields in the tab has this value empty, they will be ordered in the same way as in edit view; if some of them have it and some other ones do not, the ones having it will be placed before the other ones. This value can be managed through the Grid Sequence tab, which works in a similar way as Field Sequence one does.
Sincronizza Terminologia
In the previous steps we added information which should be translatable. To support this the new columns and fields they need to be linked to a so called Element. An Element in Openbravo ERP is used to maintain translatable labels. For more information see the Element and Synchronize Terminology article.
To link the new column and field to a label (i.e. an Element) run the Synchronize Terminology process. Synchronize Terminology is located in the Application Dictionary menu, click the menu option and then the ok in the pop-up window:
After synchronizing the terminology there should be a new Element record.
The label is still set to the rather technical column name. So let's change the label. Go to the Element window (Application Dictionary > Setup > Element) and find the new Element (search using the column name: EM_HT_Contact_Info). Then change the labels as displayed below.
Esporta Database
Now our changes have to be exported to XML. Open a command window/shell and go to the Openbravo ERP development project and then execute the following task:
ant export.database
See the database development build tasks for more information. This ant-build should finish with this message:
BUILD SUCCESSFUL
Now it is time to rebuild Java and other files.
Step di Compilazione
The definition in the Application Dictionary is complete. The last remaining step is to generate the source code which will handle our new field and column. Openbravo ERP has one overall build task which can always be ran (smartbuild). This build task analyzes the changes in the Application Dictionary and only regenerates the parts which need to be regenerated. To run this task do:
ant smartbuild
After a few minutes the build step is finished. If you have Eclipse and you open it at this point it is best to refresh the workspace because the ant-task will have created new files or has updated files.
Il Risultato
Next start Openbravo ERP and navigate to the Warehouse window. There you should something like this:
As you can see the new field is present and editable!
This concludes this part of the how-to. The next sections continue with examples on how to add other types of fields, nl. reference fields and combo-boxes. They are a bit different because they also require new data types (=reference) to be defined.
Aggiungere un campo combo box a una Scheda
In this part of the how-to we will be adding a new column to the Location table and a new field to the Location Tab/Window. The Location window can be found at General Setup > Application. The new field will be called Location Type and it will be a combo box with the following fixed values:
- Office
- Postal
- Other
Specificare il contenuto della Combo-box: Riferimento Lista
Before we can add the column/field first the type has to be defined. Column types are defined in the Application Dictionary AD_Reference table. See the screenshot below.
Some things to note:
- The combo-box module has been selected.
- The name of the reference starts with the module dbprefix, this prevents name clashes if other modules add the same reference.
- As we are adding a combobox with fixed values the validation type is: list validation.
For a detailed description on References see the Data model reference.
The next step is to add the three values of the combo-box, this is done in the List Reference (see hyperlink in the top of the Reference window).
For more information see the AD_Ref_List table description.
The search key of the list reference again starts with the module prefix to prevent unique constraint violations when other modules also add a location type list reference value.
Aggiungere una colonna
The steps to add a combo-box column are the same as for the Text field described above. For this part of the how-to the column has to be added to the C_Location table. Some other points:
- The name of the column must start with EM_ and then the dbprefix, for example EM_CB_Location_Type.
- The SQL type needs to be set to varchar(60), all list value columns should use this SQL type.
- The new column is nullable, so null is allowed.
In PostgreSQL this column is created with the following SQL:
ALTER TABLE c_location ADD COLUMN EM_CB_Location_Type varchar(60);
Now login into Openbravo ERP and go to: Application Dictionary > Table and Columns (if you don't see this menu option then your user does not have enough privileges, change to an administrator role). Find the c_location table and go to the detailed view. Click on the 'Create columns from DB' button.
The system should report back that one column has been created (Created == 1). Click on the Columns link in the top, you should see the em_cb_location_type column. Click on it to edit its details. You can see that the correct module has been selected (the dbprefix is used for that).
Then make the following changes:
- Set a description and help text.
- Set reference to list.
- Set the Reference Search Key to the reference record created earlier, CB_Location_Type.
The screenshot below shows the column after these changes have been made.
To make sure that the changes do not get lost execute the export.database task. Open a command window/shell and go to the Openbravo ERP development project and then execute the following task:
ant export.database
This will create the relevant directory for the module in the modules directory inside the Openbravo ERP development project. The created directory should contain the XML files which correspond to the changes we have been doing until now.
Step rimanenti
The remaining steps are the same as for adding a Text field to a window:
- Add the fields to a window/tab and set the sequence.
- Execute Synchronize Terminology to synchronize the translatable labels with the central label table.
- Export the database to store your changes.
- Rebuild the window using ant smartbuild.
Il Risultato
Next start Openbravo ERP and navigate to the Location window. There you should see something like this:
As you can see the new field is present and editable!
This concludes this part of the how-to. The next part of the how-to will describe how to add a new reference field to a tab.
Aggiungere campi Riferimento a un Scheda
In this part of the how-to we will be adding two new reference fields to the Warehouse window. This window can be found at Warehouse Management > Warehouse and Storage Bin (if you can't find the window in the menu then you probably have to change role).
The two new fields:
- A Shipping Company field (the default shipping company for that warehouse).
- A Business Partner, to simulate consignment inventory, the inventory in this warehouse is owned by this business partner.
The shipping company field will be displayed as a combo box, the business partner field as a selector, a pop-up.
Aggiungere una colonna
The first step is to add the columns to the M_Warehouse table so that we have a place to store the data we will be entering in the window.
There is a separate howto on how-to add a column to an existing table, see the how-to add columns to an existing table article. The steps to create a new column are almost the same as for a Text field (described above). The only difference is that also foreign key constraints have to be defined in the database (as we are adding reference fields here).
To create the column in the database you can use any tool you like, your favorite database explorer or command line tools provided by the database server. For this how-to the column has to be added to the M_Warehouse table. Some other points:
- The name of the column must start with EM_ and then the dbprefix defined for the module (see How to create and package a module for more details), for example EM_HT_Shipping_Company and EM_HT_Business_Partner.
- The SQL type we select will be varchar(32), this is the mandatory size for reference columns.
- Create foreign keys for both columns, also the FK needs the EM_ prefix and the dbprefix from the module (in this example we will use HT).
- For this how-to this column is nullable, so null is allowed.
In postgress the columns are created with the following SQL:
ALTER TABLE m_warehouse ADD COLUMN EM_HT_Shipping_Company varchar(32); ALTER TABLE m_warehouse ADD COLUMN EM_HT_Business_Partner varchar(32); ALTER TABLE m_warehouse ADD CONSTRAINT em_ht_shipping_company FOREIGN KEY (em_ht_shipping_company) REFERENCES m_shipper (m_shipper_id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION; ALTER TABLE m_warehouse ADD CONSTRAINT em_ht_business_partner FOREIGN KEY (em_ht_business_partner) REFERENCES c_bpartner (c_bpartner_id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION;
Then login into Openbravo ERP and go to Application Dictionary > Table and Columns (if you don't see this menu option then your user does not have enough privileges, change to an administrator role). Find the M_Warehouse table and go to the detailed view. Click on the 'Create columns from DB' button.
The system should report back that two columns have been created (Created == 2). Click on the Columns link in the top, you should see the two new columns.
We will change the automatically created definition in the next step.
Aggiungere un nuovo valore di Riferimento
This section of the how-to is only required if the reference used in the column definition does not exist yet. For the Shipping Company example this is the case. The Application Dictionary Reference manual describes in some more detail how to add Table References. Here we will just give a summary.
Goto to the Application Dictionary > Reference window and click the New button, then enter a name and description, select Table Definition, select the correct module and click the save button.
The next step is to define for which table the reference is defined. To do this click the Table Reference link in the top. Press the new button and create a new record as defined below.
Modificare la definizione colonna
Now it is time to update the column definitions which has been created automatically in the 'Create columns from DB' step:
Go to the M_Warehouse table (Application Dictionary > Tables and Columns) and the Columns. Find the two new columns: EM_HT_Shipping_Company and EM_HT_Business_Partner.
Click on each column and make the following changes:
- EM_HT_Shipping_Company:
- Set the description and help.
- Set the Reference to Table and the Reference Search Key to M_Shipper (the one created above).
- EM_HT_Business_Partner:
- Set the description and help.
- Set the Reference to: Search and the Reference Search Key: Business Partner, this will map in the UI to a field with a selector button with a pop-up to find a business partner.
You can see that the correct module has been selected (the dbprefix is used for that).
The Application Dictionary Reference gives a lot of details about how to set the Reference values in the column. |
To make sure that the changes do not get lost execute the export.database task. Open a command window/shell and go to the Openbravo ERP development project and then execute the following task:
ant export.database
This will create the relevant directory for the module in the modules directory inside the Openbravo ERP development project. Check out the modules directories in your Openbravo ERP development project.
Steps rimanenti
The remaining steps are the same as for adding a Text field to a window:
- Add the fields to a window/tab and set the sequence.
- Execute Synchronize Terminology to synchronize the translatable labels with the central label table.
- Export the database to store your changes.
- Rebuild the window using ant smartbuild.
Il Risultato
Next start Openbravo ERP and navigate to the Warehouse window. There you should see something like this:
As you can see the two new fields are present at the bottom. The shipping company field is a combo-box, the business partner field is a search field. When you click the button next to the business partner field the business partner selector window opens.
This concludes this how-to.
Languages: |