If you are a creating custom objects and applications in TPAE you may need at some point to create a child table like the Subassemblies in the Assets application.
Let's pretend we have a parent table called TB1 and a child table called TB2.
- TB1: Parent table
- TB1ID: Identifier of records in TB1
- ...
- TB2: Child table
- TB2ID: Identifier of records in TB2
- TB1ID: Reference to the parent record in TB1 table
- ...
In order to have the child table to behave correctly is to 'link' in some way the child rows to the parent object. If not doing this the child records will disappear as soon as you save the record.
Basic method using Database Configuration and Application Designer
First of all you need a relationship from the TB1 table to the TB2 records. In Database Configuration define the following relationship in object TB1:
- Relationship: TB2
- Child Object: TB2
- Where Clause: TB1ID=:TB1ID
The last important step is to initialize the TB2.TB1ID field on child records. To achieve this, add a Default Value control with the following configuration:
- Attribute: TB1ID
- From Data Source ID: results_showlist
- From Attribute: TB1ID
Alternative method using Java
An alternative method is to initialize this link in the child Mbo using Java. Here is how the child Mbo class should look like.
public class Tb2Mbo extends Mbo implements MboRemote
{
public Tb2Mbo(MboSet ms) throws MXException, RemoteException
{
super(ms);
}
public void add() throws MXException, RemoteException
{
super.add();
MboRemote ownerMbo = getOwner();
if(ownerMbo != null)
{
String tb1id = ownerMbo.getString("tb1id");
setValue("tb1id", tb1id, NOACCESSCHECK|NOVALIDATION_AND_NOACTION);
}
}
}
Source:http://maximodev.blogspot.com/2013/05/child-table-in-application-designer.html
Tidak ada komentar:
Posting Komentar