how to insert the record from one table to another...

Hi,

We have created two tables called applicant and selected with similar field

now once the applicant is selected the details of the particular candiate(ie the entire row) should go into the selected table when a convert button is clicked.

Please help in how to proceed…

You can utilize the “TRANSFERFIELDS” function:

This is what the OnlineHelp tells about the function:

TRANSFERFIELDS (Record)

Use this function to copy all matching fields in one record to another record.

Record.TRANSFERFIELDS(FromRecord [, InitPrimaryKeyFields])

Record

Data type: record

The record to copy the contents of the fields in FromRecord to.

FromRecord

Data type: record

The record from which to copy.

InitPrimaryKeyFields

Data type: Boolean

Default value: True

Comments

TRANSFERFIELDS copies fields based on the Field No. property of the fields. For each field in Record (the destination), the contents of the field with the same Field No. in FromRecord (the source) will be copied, if such a field exists.

The fields must have the same data type for the copying to succeed (text and code are convertible, other types are not.) There must be room for the actual length of the contents of the field to be copied in the field to which it is to be copied. If any of these conditions are not fulfilled, a run-time error will occur.

If the InitPrimaryKeyFields parameter is set to false, the TRANSFERFIELDS function will not change the timestamp or the Primary Key fields of the destination record.

If the InitPrimaryKeyFields parameter is set to true, and the records are in the same table, the TRANSFERFIELDS function will change both the timestamp and the Primary Key fields of the destination record.

If the InitPrimaryKeyFields parameter is set to true, and the records are not in the same table, the TRANSFERFIELDS function will change the Primary Key fields of the destination record (if the fields fulfill the conditions specified above) but the timestamp of the destination record will not be changed.

BLOB Fields

If you are copying a record that contains a BLOB field, you must calculate the BLOB field before it can be copied with the rest of the record.

IF Mytable.BLOB.HASVALUE THEN
Mytable.CALCFIELDS(BLOB);

Hi Thomas,

Thanks for your reply…
we tried your solution…

I created a record types for both the tables n included the following code in the button.

emp.TRANSFERFIELDS(app,true);

but the records of app is not inserted into emp.

The fields in both the tables have same field No and datatypes…

Can you suggest where we went wrong…

Yes, after performing the TRANSFERFIELDS, you still need to call the “INSERT” on the new record.

emp.TRANSFERFIELDS(app,true);

emp.insert;

these are the 2 lines tat we included in the button.But still the record is not inserted.

Hi Bavani,

Do you get an error?

Also you are using a variable “app” - have you populated this variable?

Can you give a description of the form when the button is located.

hi

you are telling , the code is inserted in the button … can u clarify what is the souce table if you are adding the code in the form.

Hi Thomas,

Im not getting any error.

app is the record type for application table.

Applicant card is the form i have created for application table.In that form i have all the fields from applicant and a button called convert.

When i click the convert button the applicant need to be converted into employee and the record of that particular candiate needs to be copied into employee table.

Hi Bavani,

The appicant record will be stored in the system variable Rec so what you need is

If NOT Emp.GET( “No.” ) then // Assuming you are using No. as the primary key and test if employee record is there

begin

emp.TRANSFERFIELDS( Rec, TRUE ); // or if identical Emp := Rec;

emp.INSERT;

end;

Hi Dave,

Thank u very much.we got it.

the record is inserted…

thanks a lot…

The records are inserted with the applicant No series into employee table.

But the records needs to be inserted with the employee series.

Please suggest on how to proceed

Hi Bavani,

Assuming you are use the standard employee table or have code in the OnInsert trigger to get the next number from the number series then all you need to do is add

Emp.“No.” := ’ ';

directly before the INSERT statement

Happy St. Patrick’s Day [<:o)]

Hi Dave,

we tried wih the following code

IF NOT emp.GET(AppId) THEN
BEGIN
emp.TRANSFERFIELDS(Rec,TRUE);
emp.“emp id”:=’’;
emp.INSERT;
END;

Here emp table has automatic No series generation.

But when the record is transferred the empid field is blank and all others are inserted.

Its not taking the next number of emp table.

please suggest

You need to call INSERT(TRUE) instead of INSERT; on the emp-Record.

The automatic numbering is maintained by code in the OnInsert trigger of the table. If you do not call the trigger (by the TRUE parameter) the code will not be executed and no number will be assigned.

Thank you Thomas…

The Nos are inserted.