In this guide, we will show how to create a table event on brainlowcode platform.
Create these tables given below using New Editor -> SQL DDL Command for VCS
. After creating, you need to import them bu clicking burn button. (Table)
create table contact_notebook (contact_id integer not null,name character varying(1024) not null,surname character varying(1024) not null,lkp_gender integer,adress character varying(1024),birth_date date,email character varying(1024),active_flag smallint not null default 0,version_no integer NOT NULL DEFAULT 1,insert_user_id integer NOT NULL DEFAULT 1,insert_dttm timestamp without time zone NOT NULL DEFAULT ('now'::text)::timestamp without time zone,version_user_id integer NOT NULL DEFAULT 1,version_dttm timestamp without time zone NOT NULL DEFAULT ('now'::text)::timestamp without time zone,CONSTRAINT pk_contact_notebook PRIMARY KEY (contact_id));create sequence seq_contact_notebook ;
create table phone_number (phone_number_id integer not null,table_id integer not null,table_pk integer not null,number character varying(1024) not null,active_flag smallint not null default 0,version_no integer NOT NULL DEFAULT 1,insert_user_id integer NOT NULL DEFAULT 1,insert_dttm timestamp without time zone NOT NULL DEFAULT ('now'::text)::timestamp without time zone,version_user_id integer NOT NULL DEFAULT 1,version_dttm timestamp without time zone NOT NULL DEFAULT ('now'::text)::timestamp without time zone,CONSTRAINT pk_phone_number PRIMARY KEY (phone_number_id) );create sequence seq_phone_number;
Create forms and grids for the tables using Form Wizard. For contact_notebook
create a page named pg_contact_notebook
and add it to menu with label Contact Notebook(Page and Menu). We don't need a page for phone grid because it will be detail grid on pg_contact_notebook
page.
Set UI Component of table_id
and table_pk
to none. Click on button to open edit mode then after you made the changes click on
to commit your changes.
Uncheck Can Update?
property of table_pk
and table_id
table fields of phone_number table.
Reload cache after changes to database.
In both forms, set Initial Value of active_flag field to 1.
Now, we will add phone_number
element to frm_contact_notebook1
form. This phone_number
element will not have its corresponding table field in contact_book
table. Because we will save its value into phone_number
table. Click on button to add new form field.
As you see below phone_number
element's source field is empty. Source field is form element's corresponding table field.
Next, we will add table event to Contact Notebook page. But before that, let's prepare our code for saving phone_number value of frm_contact_notebook1 form element into phone_number table's number field. We can get the form code from New Editor -> Backend Function
. Click on button next to
frm_phone_number1
to get the code.
Copy this code:
Let's enter parameter values. First parameter is form id which is 6580 in our case (id of frm_phone_number1
). Second parameter is 2 for insert (for update it would be 1). Third parameter is form data:
table_id : contact notebook table's id
table_pk : primary key of table contact_notebook
number : phone_number element's value
active_flag : 1
So, this is our code in its final form:
var frm_phone_number1=$.postForm(6580,2,{table_id:4561,table_pk:_request.tcontact_id,number:_request.phone_number,active_flag:1});$.console(frm_phone_number1.outputFields);//.errorMap , .outputMessages
Go to Events of table contact_book and click on button.
Paste the code, set Triggers Actions as After Insert and click save.
Now, we will add grd_phone_number1
as detail grid to Contact Notebook page. Delete table_id and table_pk columns from grd_phone_number1
grid. Add table_id and table_pk as parameters to query qry_phone_number1
.
Go to Page Objects of pg_contact_notebook and click on button. Add
grd_contact_notebook1
grid if you haven't already.
Enter these configurations and click save.
We added table event to save phone number into phone_number table using contact notebook form. And we can see phone_number data in detail grid.