Hi,
I have added code to insert customer records when created in company A to company B through change company and transfer fields. Record is getting inserted in company B. Same way I have added code to modify record through change company & transfer fields. But error is thrown when I modify the record in company B which got transferred from company A.
Error shown is
Another User has modified the record for this customer after you retrieved it from the database.
Code
Customer2.CHANGECOMPANY(Companyname);
Customer2.RESET;
Customer2.LOCKTABLE;
Customer2.SETRANGE("No.",Rec."No.");
IF Customer2.ISEMPTY THEN BEGIN
Customer2.INIT;
Customer2.TRANSFERFIELDS(Rec);
ELSE BEGIN
IF NOT Customer2.ISEMPTY THEN BEGIN
Customer2:=Rec;
Customer2.MODIFY;
CusCounter1+=1;
ModArr[CusCounter1]:=Companyname;
END;
END;
Customer2.INSERT;
*This post is locked for comments
This following Code works for me... Thanks for all your valuable replies.
Rec.MODIFY;
Customer2.CHANGECOMPANY(Company);
Customer2.RESET;
Customer2.LOCKTABLE;
Customer2.SETRANGE("No.",Rec."No.");
IF Customer2.FINDFIRST THEN BEGIN
Customer2.TRANSFERFIELDS(Rec);
Customer2.MODIFY;
END;
Customer2:=Rec; -> WHY THIS?? use TRANSFERFIELDS
Customer2.MODIFY;
send your updated code so we can help further
Hi anandb313@gmail.com,
Try below code:
Customer2.CHANGECOMPANY(Companyname);
Customer2.INIT;
IF Customer2.GET(Rec."No.") THEN BEGIN //Existing customer -> update info
Customer2.TRANSFERFIELDS(Rec);
Customer2.MODIFY;
CusCounter1 += 1;
ModArr[CusCounter1] := Companyname;
END
ELSE BEGIN //Not existing customer -> add new
Customer2.TRANSFERFIELDS(Rec);
Customer2.INSERT;
END;
Check if this works (difficult to see your requierements):
//In the ONINSERT trigger of the Customer table in the company where you create the ITEM
Customer2.CHANGECOMPANY(CompanyName);
if Customer2.GET(Rec."No.") then
begin
Customer2.TRANSFERFIELDS(Rec);
Customer2.MODIFY;
end
else
begin
Customer2.INIT;
Customer2.TRANSFERFIELDS(Rec);
Customer2.INSERT;
end;
Thanks for the reply. I get the same error still.
on debugging, error is thrown in
Customer2.MODIFY;
Thanks for the reply. No still I get the error when I change the customer record.
In this code seems that the INSERT is executed always, also after the MODIFY. Reorganize your code:
Customer2.RESET;
Customer2.LOCKTABLE;
Customer2.SETRANGE("No.",Rec."No.");
IF Customer2.ISEMPTY THEN
BEGIN
Customer2.INIT;
Customer2.TRANSFERFIELDS(Rec);
Customer2.INSERT;
END
ELSE
BEGIN
Customer2:=Rec;
Customer2.MODIFY;
CusCounter1+=1;
ModArr[CusCounter1]:=Companyname;
END;
Customer2.CHANGECOMPANY(Companyname); Customer2.RESET; Customer2.LOCKTABLE; Customer2.SETRANGE("No.",Rec."No."); IF Customer2.ISEMPTY THEN BEGIN Customer2.INIT; Customer2.TRANSFERFIELDS(Rec); Customer2.INSERT; ELSE BEGIN Customer2.FINDFIRST; Customer2:=Rec; Customer2.MODIFY; CusCounter1+=1; ModArr[CusCounter1]:=Companyname; END;
Above should work :-)
Please tell what line in your code is throwing the error
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156