Another user has modified.....

TLCTLC Member Posts: 13
I run this codeunit as part of an email notification system. It works the first time, but subsequent attempts to run this codeunit in the job queue throws the error:

Another user has modified the record for Sales Shipment Header No. 'xxxxx' after you retrieved it from the database.

Re-enter the changes in the updated window or start the activity again.


Here's the code:


SalesShptHeader.RESET;
SalesShptHeader.SETCURRENTKEY("Customer Email Sent","Delay Customer Email");
SalesShptHeader.SETFILTER("Customer Email Sent",'No');
SalesShptHeader.SETFILTER("Delay Customer Email",'No');
IF SalesShptHeader.FINDSET(TRUE,TRUE) THEN
REPEAT
SalesShptHeader2 := SalesShptHeader;
SalesShptHeader2.SETRECFILTER;
REPORT.RUN(xxxxx,FALSE,FALSE,SalesShptHeader2);
SalesShptHeader2."Customer Email Sent" := TRUE;
SalesShptHeader2.MODIFY;

UNTIL SalesShptHeader.NEXT = 0;

Is it my modify statement that is causing the problem? I thought FINDSET(TRUE,TRUE) was supposed to be able to process this.

Perhaps it was because other users are posting the shipments, hence adding the first line: SalesShptHeader.RESET;

Answers

  • TLCTLC Member Posts: 13
    I fixed this by locking the table at the beginning of the code:

    SalesShptHeader.LOCKTABLE;
Sign In or Register to comment.