Error when inserting records: another user has modified the record

I have a table, on some action i have to delele all the records and insert fresh records from another table means simple.

for this , first i am deleting records and after that i insert new records but at last i am getting error.

for delete i am doing this

DELETE============================

Bssi_rMilestoneDetailsInsert.RESET;
Bssi_rMilestoneDetailsInsert.SETFILTER(BssiBillingArcbScheduleNo, BssiBillingArcbScheduleNo);
Bssi_rMilestoneDetailsInsert.SETFILTER(BssiBillingLineNo,FORMAT(BssiBillingLineNo ));
IF Bssi_rMilestoneDetailsInsert.FINDSET THEN BEGIN
REPEAT
Bssi_rMilestoneDetailsInsert.GET(Bssi_rMilestoneDetailsInsert.BssiBillingArcbScheduleNo,Bssi_rMilestoneDetailsInsert.BssiBillingLineNo, Bssi_rMilestoneDetailsInsert.“Line No.”);
Bssi_rMilestoneDetailsInsert.DELETE(FALSE);
UNTIL Bssi_rMilestoneDetailsInsert.NEXT=0
END;

end DELETE==========================

for insert fresh records============================

ctr:=1;

REPEAT
Bssi_rMilestoneDetailsInsert.INIT;
Bssi_rMilestoneDetailsInsert.“Line No.”:=ctr;
Bssi_rMilestoneDetailsInsert.BssiBillingArcbScheduleNo:=Bssi_rScheduleLines.BssiArcbBillingScheduleNumber;
Bssi_rMilestoneDetailsInsert.BssiBillingLineNo:=Bssi_rScheduleLines.“Line No.”;

Bssi_rMilestoneDetailsInsert.INSERT;
ctr:=ctr+1;
UNTIL Bssi_rMilestoneItemLines.NEXT=0;

'==========================================

after completion , i get error :

another user has modified the record for this table, after you reterived it from database. enter your chages again in the updated window,or start interupted again.

i have done lots of things to recitfiy to solve this… but FAILS

PLEASE HELP !!!

(Subject changed by admin)

Sure it fails, but exactly what is it that you’re trying to do? In the first loop you both FINDSET and get the same VARIABLE? Then you delete the record again. Not knowing the primary key makes the logic difficult to understand.
You may end up with records not deleted.

Next you make a loop on Bssi_rMilestoneItemLines. But you don’t have a FINDSET - nor did you set any filters.

As to the actual error, then without know more, like which object you have this code and how you call it, then I cannot say more.

After using SetFilter and repeat until why you are using Get function again? it is just extra line of code.
Regarding your error 2 different code are trying to modify the same table at same time try to avoid that.

I deleted the get from the loop now for deletion the records, I wrote:
primary Keys for following table are :BssiBillingArcbScheduleNo,BssiBillingLineNo,“Line No.”

and i want to delete all the records for one schedule and billing line no.

Bssi_rMilestoneDetailsInsert.RESET;
Bssi_rMilestoneDetailsInsert.SETFILTER(BssiBillingArcbScheduleNo, BssiBillingArcbScheduleNo);
Bssi_rMilestoneDetailsInsert.SETFILTER(BssiBillingLineNo,FORMAT(BssiBillingLineNo ));
IF Bssi_rMilestoneDetailsInsert.FINDSET THEN BEGIN
REPEAT
Bssi_rMilestoneDetailsInsert.DELETE(FALSE);
UNTIL Bssi_rMilestoneDetailsInsert.NEXT=0
END;

but at the time of insert new records, I am not understanding that what should i filter and why i need filter the records because now table is empty as i deleted the records

Hi Sahil,

No need for a repeat next loop when deleting. Instead of:

IF Bssi_rMilestoneDetailsInsert.FINDSET THEN BEGIN
    REPEAT
        Bssi_rMilestoneDetailsInsert.DELETE(FALSE);
    UNTIL Bssi_rMilestoneDetailsInsert.NEXT=0

Just use:

Bssi_rMilestoneDetailsInsert.DELETEALL(FALSE);

Hi Sahil you 've deleted the records from table record Bssi_rMilestoneDetailsInsert but not from Bssi_rScheduleLines so this Rec Variable is still holding values.
You should apply filter related to the record variable Bssi_rScheduleLines. The filtering you apply for Bssi_rScheduleLines should have a field that is related to Bssi_rMilestoneDetailsInsert once filtering is done use FINDSET and do REPEAT UNTIL LOOP to insert all records from Bssi_rScheduleLines to Bssi_rMilestoneDetailsInsert .

Bssi_rScheduleLines and Bssi_rMilestoneDetailsInsert variables pointing to two diff tables .

i checked with deleteALL but problem is still persist.

i also tried with new logic, now i am modify the existing records on basis of keys and if record doen’t present then i insert the new records. now what happend, it refresh the list page records but not which is selected, but when i clicked on refresh button then it shows all updated records. now how can i resolve this problem

If you’re writing this code in Page then use at end of code CurrPage.Update

I also meant the same. You can filter on other table which is not deleted and move those value to the table which you deleted after applying filter.

yes i am writing this code in page… but already tried with currpage.update… but fails
:frowning:

Hi Sahil
I think you problem is not solved yet, sometimes guys get busy and it might take long time to get proper help, mean while i suggest you look similar functions in the Demo data base there are tones in it and you might get your solution there.

now i am not delete any thing. now i match the records with table if found then update with new recoreds if not found then insert the fileds
my page is type of list page.

code is :
IF Bssi_rMilestoneItemLines.FINDSET THEN BEGIN
REPEAT
IF Bssi_rMilestoneDetailsInsert.GET(BssiBillingArcbScheduleNo,BssiBillingLineNo,ctr) THEN BEGIN
Bssi_rMilestoneDetailsInsert.deleted:=FALSE;
Bssi_rMilestoneDetailsInsert.MilestoneItemDesc :=Bssi_rMilestoneItemLines.“Item Description”;

Bssi_rMilestoneDetailsInsert.MODIFY;
END ELSE BEGIN

Bssi_rMilestoneDetailsInsert.INIT;
Bssi_rMilestoneDetailsInsert.BssiBillingArcbScheduleNo:=Bssi_rScheduleLines.BssiArcbBillingScheduleNumber;
Bssi_rMilestoneDetailsInsert.BssiBillingLineNo:=Bssi_rScheduleLines.“Line No.”;
Bssi_rMilestoneDetailsInsert.“Line No.”:=ctr;

Bssi_rMilestoneDetailsInsert.deleted:=FALSE;
Bssi_rMilestoneDetailsInsert.MilestoneItemDesc :=Bssi_rMilestoneItemLines.“Item Description”;

Bssi_rMilestoneDetailsInsert.INSERT;
END;

ctr:=ctr+1;
UNTIL Bssi_rMilestoneItemLines.NEXT=0;
END;

it updates the records in database … but on UI, it doesn’t refresh the selected record line in list. when i click on refresh button then a popup comes for update the datasource. and load the latest records.

Old Code:
Bssi_rMilestoneDetailsInsert.RESET;
Bssi_rMilestoneDetailsInsert.SETFILTER(BssiBillingArcbScheduleNo, BssiBillingArcbScheduleNo);
Bssi_rMilestoneDetailsInsert.SETFILTER(BssiBillingLineNo,FORMAT(BssiBillingLineNo ));
IF Bssi_rMilestoneDetailsInsert.FINDSET THEN BEGIN
REPEAT
Bssi_rMilestoneDetailsInsert.GET(Bssi_rMilestoneDetailsInsert.BssiBillingArcbScheduleNo,Bssi_rMilestoneDetailsInsert.BssiBillingLineNo, Bssi_rMilestoneDetailsInsert.“Line No.”);
Bssi_rMilestoneDetailsInsert.DELETE(FALSE);
UNTIL Bssi_rMilestoneDetailsInsert.NEXT=0
END;


Try this. Do NOT use the GET-function because you allready have the record represented With FINDSET/NEXT function:

With TEMP_Bssi_rMilestoneDetailsInsert
SETFILTER(BssiBillingArcbScheduleNo, BssiBillingArcbScheduleNo);
SETFILTER(BssiBillingLineNo,FORMAT(BssiBillingLineNo ));
IF FINDSET THEN
REPEAT
DELETE;
BssiBillingLineNo := Bssi_rScheduleLines.“Line No.”;
INSERT;
UNTIL NEXT=0


If it NOT work then try with a help-table defined as TEMP_Bssi_rMilestoneDetailsInsert:

With Bssi_rMilestoneDetailsInsert DO BEGIN
SETFILTER(BssiBillingArcbScheduleNo, BssiBillingArcbScheduleNo);
SETFILTER(BssiBillingLineNo,FORMAT(BssiBillingLineNo ));
IF FINDSET THEN
REPEAT
TEMP_Bssi_rMilestoneDetailsInsert := Bssi_rMilestoneDetailsInsert:
TEMP_Bssi_rMilestoneDetailsInsert := BssiBillingLineNo := Bssi_rScheduleLines.“Line No.”;
TEMP_Bssi_rMilestoneDetailsInsert :=INSERT;
UNTIL NEXT=0;

DELETEALL;
END;

With TEMP_Bssi_rMilestoneDetailsInsert DO BEGIN
IF FINDSET THEN
REPEAT
Bssi_rMilestoneDetailsInsert := TEMP_Bssi_rMilestoneDetailsInsert:
INSERT;
UNTIL NEXT=0;
DELETEALL;
END;

You do not have to delete from temptable because it is defined as temporary and it will be empty after completion of code