Version 4.24 introduced a new feature to the Custom Forms, called SubForms. With the SubForm feature, a user may edit a table within a form. In order to utilize this new tool, the user is required to link two custom forms which target two different tables and are linked via a Foreign Key relationship. Below we will explain how to do this link and demonstrate how to use this feature.
Using SubForms
For this example, we are using the following model
In this model, there is a basket which is one order. This basket can contain one or more requests. Each request can contain one or more products. So for example, if you imagine a supermarket basket that contains 6 eggs and 4 apples, the request would be for 6 of the product egg and 4 of the product apples.
How to Create SubForms
As mentioned already, in order to use the subforms you need to create first the forms as usual, as described in the Custom Forms article. The only thing different is that in the Form Fields excel sheet, now you will find a new column SUBFORM_CODE, in which you type the code of the SubForm you created. For this article we will create two forms the ADD_BASKET and the ADD_REQUEST. With the ADD_BASKET form, the user is creating a Basket, which will contain requests, and specify all the characteristics like request date, who is the requestor etc. In the ADD_REQUEST, the user is creating a request for the products as mentioned above, and assigning it to an existing basket via the Basket ID.
Note: Every basket may contain multiple requests.
In order to make the link between the main (ADD_BASKET) form and the SubForm (ADD_REQUEST), you need to add a new row in the Form Fields sheet of the main form, as if you are about to add a new field but in this case you have to leave the FIELD_CODE empty.
A small note, on this is the SEQUENCE column. In this example we have assigned the subform field as the third in this form. This will determine the order in the view data page and the exact place of where the table to enter data using the subform will appear. A suggestion is to set it as last, but we will demo the both cases in order to check the differences.
How to Use SubForms
To demonstate the SubForms feature we will use an example of two forms the ADD_BASKET and the ADD_REQUEST, as mentioned above.
Let’s see how you may create a basket and afterwards how you may add products in this basket, without opening the ADD_REQUEST form.
In the print screen below you may see that we are creating a new Basket. We have assigned a unique ID for the basket (BASKET_ID_FULL), and afterwards we enter some data to all the other fields and then we may save our entry.
After saving our entry, we are able to view our data and from that view, users have now the ability to view or add new data through the subform function.
In the picture above, the subform field is the third in the sequence.
In the picture above, the subform field is set as the last in the sequence.
By clicking Add you will be the SubForm will open (ADD_REQUEST in this case) for that particular basket as you may see below and you may proceed in creating a new product for that basket.
Another way to use the SubForms is while editing the parent. If we edit a basket and scroll to the bottom, we can see that there is a grid containing the requests for this basket. of that entry you will not be able just to see the save option as usual but also the Add new record option.
By clicking the Add new record the SubForm will launch in a pop up window where you may create you entry as usual. See the screenshot below.
When you’ll finish creating your entries using the SubForm, then you click the update button and you will be redirected back to the data view page.
Below is an example of how what you will see when you will make some entries using the subform feature.
On the left of the existing records is the Subforms Action Panel
If you select View Record then the record will be opened but you will not be able to edit it.