Saving the parents table fields to the child table

Hi all,

Is there an way for copying the parents table fields to the child table.I have a screen with a parents grid and child grid.The user enters the parents grid with fields like emplid,dimension (1),dimension(2) etc.Then the user will add a new line in the child grid.That time the upper grid fields need to be copied in the child grid field.Please let me know if my explanation not clear.

Can u elaborate your Question Pls…

Thanks for your reply.

There are 2 join grids in a form.A parent grid with fields of tele no,Emplid,Dimension(1),Dimension(2),Dimension(2),Account etc from the Table A And the same way we have a child grid there is a tele no ,Date,Emplid,Dimension(1),Dimension(2),Account etc from Table B.So i joined them botha nd made tele no as primary key.Now on the top Parent grid i am saving some details with all the fields as stated above.While creating a new line in the child grid system should automatically select the top grid empl id,dimension(1),dimension(2),Account values to the child grid table and should appear.So on creating a new line i need to write a method to do this process.Please let me know if u need further explanation

You can add a method on Table B named as initFromTableA with TableA as table parameter. In this method, copy data required from TableA columns to TableB columns. Call initFromTableA method in write method of TableB datasource of the form.

Hello Sindhu, Need to make use of initfromtable method i.e for example,in this case need to get the data from the parent table to childtable. Let be Parent Table - Table_Parent and Child Table - Table_Child Now add the method in the in the child Table as initFromTable_Parent Void initFromTable_Parent(Table_Parent _tableParent) { this.empId = _tableParent.empid; this.Dimension[1] = tableParent.Dimension[1]; this.Dimension[2] = tableParent.Dimension[2] } try this.

Thanks for the response Naresh.but i tried my putting it into initform method in the child table.But its not saving anything also its not touching the break point in the method as well.When i enter the data in the parent table and when i create new line in the child table i wanted some of the field from the parents table to be copied to the child table.

Hi,

Make a table method handling the copying (see any table method initFrom), like childTable.initFromParentTable and then override the childTable.initValue:

void initValue()
{
;
super();

this.initFromParentTable();
}

Thanks .Now the code is navigatin to my break point but still its not showing the childtable as recid=0;

i wrote a method as

Void initFromcaeTeleMaster(caeTeleMaster _caeTeleMaster)
{
this.ProjId = _caeTeleMaster.ProjId;
//this.EmplId = _caeTeleMaster.EmplId;
this.Dimension = _caeTeleMaster.Dimension;
//this.Dimension[1] = tableParent.Dimension[1];
//this.Dimension[2] = tableParent.Dimension[2]
}

_caeTeleMaster is showing as recid = 0;How to grab the details of the parents records and copy the same to the child

Hi,

You are not passing the ID value connecting the parent and child to the init method. Write a new method on the child table:

caeTeleMaster caeTeleMaster()
{
caeTeleMaster caeTeleMaster;
;
select firstonly caeTeleMaster
where caeTeleMaster.ID == this.ID;

return caeTeleMaster;
}

or

caeTeleMaster caeTeleMaster()
{
;
return caeTeleMaster::find(this.ID);
}

And then modify your init method a bit

Void initFromcaeTeleMaster()
{
caeTeleMaster _caeTeleMaster = this.caeTeleMaster();
;
this.ProjId = _caeTeleMaster.ProjId;

Thanks for the response.But while saving the caeTeleMAster method it throws an error saying The operand is not compatible with the type of the function.

I wrote find method and tried with the other method as well.It was throwing error.

Write in form child datasource initvalue method. ChildDatasource.field = parentDataSource.field. Make sure there is relation between parent and child table and join source property assigned in child data source in form. Regards, Kuppusamy S

Write in form datasource initvalue method. ChildDatasource.field = parentDataSource.field. Make sure there is relation between parent and child table and join source property assigned in child data source in form. Regards, Kuppusamy S

Hi,

Your relation fields, which I wrote as “ID” in the example, are not of the same type?

No i did not write relation field as ID.I wrote teleno as relational field.since that is the field which has link between the 2 tables.

Hi,

odd, that should work… could you paste your code?