May 2, 2013

Child table in Application Designer

This article is obsolete. Please refer to this one.

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
    • ...
The fundamental concept is to have a field in the child table that points to a specific row in the parent table. In our example such field is TB2.TB1ID.

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
In the Application Designer you have to use this relationship in the child table.
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
This will set the 'link' between parent and child tables.

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);
    }
  }
}

6 comments:

  1. Lets say you create child object for ASSET MBO (to be shown in ASSETS application). How to populate ASSETNUM from parent record (ASSET) to child record without using a java code?

    ReplyDelete
    Replies
    1. @Tomasz

      Hi, if you are using Maximo 7.5 then - go to DB Config application, open the Child Object, go to Child Attribute. Provide Default Value for Child Attribute as &OWNER&.ASSETNUM

      Before applying above step, you need to have proper relationship between Parent and Child as:
      From: ASSET
      To: ChildofAsset
      where Clause: :WONUM = ChildWONUM and :SITEID = ChildSITEID

      Delete
  2. Hi,

    If I using Maximo 7.1 can i create new MBO?

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. Hi Bruno,

    I followed above tech note steps to achieve parent child relation.
    I Succeeded till some point.In application designer when I added a table in some section with Child table relationship and i have added that child table attribute to UI fileds. I haven't seen any INVALID BINDING error. So, I thought everything is perfect. But the same table section is not visible in the same parent application how ever it is visible in application designer.

    In your tech note last point(Below point) is not clear.

    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
    This will set the 'link' between parent and child tables.


    Could you clear this point and please help in resolving the issue


    Thanks..

    ReplyDelete
  5. Great information as it mentions step by step guidance. CPDESK is Online Web Development Tool Company located in Canada. Our main services include : Web based Software designing Tool, Web based Business Application, Web based SQL form designer, Corporate application form designer. For more details please visit our site - Web Based Software Application Designing Tool | CPDESK

    ReplyDelete