In this example we’ll show how to create a complete master/detail application. To create this application we’ll need to create two forms. The first one based on the table orders (Master) and the second based on the table orders_details (Detail).
Creating the Master Form:
1 - Create a new form simple application based on the table orders.
2 -On the application menu access the Field Positioning.
3 - Remove the following fields: ShipVia, ShipRegion and ShipPostalCode.
4 - On the application menu access the Layout and click on Blocks:
5 - Change the label name of the existing block to General info.
6 - Click on Create New Block.
7 - Inform the Name and Label in this case we’ll use Ship info, then click create.
8 - Inform the Name and Label in this case we’ll use Order Details, then click create.
9 - Edit the properties of the blocks to match the image bellow:
10 - On the application menu access Field Positioning and order fields the according to the image bellow:
Creating a Detail Form:
1 - Create a new form of the type Editable grid view based on the table order_details.
2 - On the application menu, click on the field positioning.
3 - Remove the fields OrderDetailsID and OrderID.
4 - On the application menu click on Fields and select the field ProductID.
5 - Change to Data type of the field to Select.
6 - Still on the field ProductID go to the Lookup Settings, On the SQL Select Statement insert the following Query of the image:
7 - Still in Fields on the application menu click on New Field.
8 - Create only one field, then click next.
9 - Change the type to Decimal, Name and Label to Total.
Creating methods in the Detail Form.
10 - On the application menu access the programming tab, then expand PHP Methods -> New Method.
11 - Create a new method called calculate_total.
12 - Insert the code from the following image:
13 - Create a new method called check_stock.
14 - Insert the code from the following image:
15 - Create a new method called update_master.
16 - Insert the code from the following image:
Creating Ajax events for the Detail Form.
17 - On the application access the option Ajax events, then click New Ajax Event.
18 - On the first option select the field that’ll be holding the event in this case discount, on the next option select the type event that’ll be used in this case onChange, then click on Create Event.
19 - On the editor call the method calculate_total.
20 - Now do the same step as the 19th but use the field ProductID this time.
21 - On the editor place the following code from the image:
22 - Now do the same step as the 19th but use the field Quantity this time.
23 - On the editor place the following code from the image:
24 - Now do the same step as the 19th but use the field UnitPrice this time.
25 - On the editor place the following code from the image:
Calling the created methods on the events of the Form
26 - On the application menu access the Events area. The same way you place events for fields, we’ll call the methods from the events of the Form.
27 - Generate the source code of the Detail Form. Click on the button Generate on the Scriptcase toolbar.
Create the link between the Master Form and the Detail Form
28 - Go back to the Master Form by click it’s tab bellow the toolbar.
29 - On the application menu click on Master/Detail, then click on New Master Detail.
30 - Insert on the Name and Label Details, then click create.
31 - Next select the Detail Form the click next.
32 - On the next step make a link passing the OrderID of both Forms, then click save.
33 - Now run the Form.