frida
June 5, 2012, 9:41am
1
Hello,
I would like to copy some records form one table to another table.
I have this code:
VendorLedgerEntry.SETFILTER(“Amount to Transfer”, ‘>0’);
IF VendorLedgerEntry.FIND(’-’) THEN
REPEAT
WITH BankTransferLine DO
BEGIN
INIT;
“Vendor No.” := VendorLedgerEntry.“Vendor No.”;
“Document No.” := VendorLedgerEntry.“Document No.”;
“Currency Code” := VendorLedgerEntry.“Currency Code”;
“Amount to Transfer” := VendorLedgerEntry.“Amount to Transfer”;
“Vendor Account No.” := VendorLedgerEntry.“Vendor Account No.”;
INSERT;
END;
UNTIL VendorLedgerEntry.NEXT = 0;
It works well, when I have only one record. The record is inserted in the target table.
But when I want to copy more than one record at the same time, I get the error message:
The Bank Transfer Line already exists. Identification fields and values: Line No.=‘12’
It seems that the program always wants to insert the record in the same line.
What is missing from my code? How to code that every record is inserted in a new line?
Thanks a lot, Frida
What is the Primary Key for BankTransferLine table?
frida
June 5, 2012, 10:01am
3
The primary key is Line No. field. I set the AutoIncrement property to Yes.
Kindly check primary key field as you have insert those fields also whenever your inserting record in ledger tables.
frida
June 5, 2012, 10:12am
5
What do you mean by that? I don’t insert records to the ledger table, but in my own table called Bank Transfer Line.
How should I check primary key field?
Should I add something to my code? I do not know what…
Try this code
VendorLedgerEntry.SETFILTER(“Amount to Transfer”, ‘>0’);
IF VendorLedgerEntry.FIND(’-’) THEN
REPEAT
WITH BankTransferLine DO
BEGIN
INIT;
“Line No.” := 0; // this will trigger the auto-increment to get the next number
“Vendor No.” := VendorLedgerEntry.“Vendor No.”;
“Document No.” := VendorLedgerEntry.“Document No.”;
“Currency Code” := VendorLedgerEntry.“Currency Code”;
“Amount to Transfer” := VendorLedgerEntry.“Amount to Transfer”;
“Vendor Account No.” := VendorLedgerEntry.“Vendor Account No.”;
INSERT;
END;
UNTIL VendorLedgerEntry.NEXT = 0;