Problem in Delete Function when Concurrent users Posting

sujatharaoo
Member Posts: 57
Hi,
In a Transfer Order Shipment Posting routine, the values are posted to GLEntry,Item Ledger Entry, and Posted Transfer order shipment Table. After posting the values Transfer Order Shipment table has to be deleted. For this requirement Coding written as follow..
"Posted Br.TransferHeader".INIT;
"Posted Br.TransferHeader".TRANSFERFIELDS("Br.TransferHeader");
"Posted Br.TransferHeader".INSERT;
"Br.TransferLine".Reset;
"Br.TransferLine".SETRANGE("Br.TransferLine".Type,"Br.TransferHeader".Type);
"Br.TransferLine".SETRANGE("Br.TransferLine"."Document No","Br.TransferHeader".No);
IF "Br.TransferLine".FIND('-') THEN
REPEAT
"Posted Br.TransferLine".INIT;
"Posted Br.TransferLine".TRANSFERFIELDS("Br.TransferLine");
"Posted Br.TransferLine"."Posting Date" := "Br.TransferHeader"."Posting Date";
"Posted Br.TransferLine".INSERT;
UNTIL "Br.TransferLine".NEXT = 0;
"Br.TransferLine".DELETEALL;
"Br.TransferHeader".DELETE;
When Concurrent users are Posting, the Posted Transfer order Shipment is also getting deleted..
How to change the code, to avoid these deletion when concurrent users are posting? Can any one Suggest me?
Thanx In Advance
In a Transfer Order Shipment Posting routine, the values are posted to GLEntry,Item Ledger Entry, and Posted Transfer order shipment Table. After posting the values Transfer Order Shipment table has to be deleted. For this requirement Coding written as follow..
"Posted Br.TransferHeader".INIT;
"Posted Br.TransferHeader".TRANSFERFIELDS("Br.TransferHeader");
"Posted Br.TransferHeader".INSERT;
"Br.TransferLine".Reset;
"Br.TransferLine".SETRANGE("Br.TransferLine".Type,"Br.TransferHeader".Type);
"Br.TransferLine".SETRANGE("Br.TransferLine"."Document No","Br.TransferHeader".No);
IF "Br.TransferLine".FIND('-') THEN
REPEAT
"Posted Br.TransferLine".INIT;
"Posted Br.TransferLine".TRANSFERFIELDS("Br.TransferLine");
"Posted Br.TransferLine"."Posting Date" := "Br.TransferHeader"."Posting Date";
"Posted Br.TransferLine".INSERT;
UNTIL "Br.TransferLine".NEXT = 0;
"Br.TransferLine".DELETEALL;
"Br.TransferHeader".DELETE;
When Concurrent users are Posting, the Posted Transfer order Shipment is also getting deleted..
How to change the code, to avoid these deletion when concurrent users are posting? Can any one Suggest me?

Thanx In Advance
Regards,
Sujatha.N
Sujatha.N
0
Comments
-
Stuff doesn't just automatically get deleted from tables just because multiple users are posting at the same time. Something is going on that perhaps those records don't get created in the first place. I'm thinking maybe a COMMIT statement somewhere, at a time between where the original docs are deleted but before the posted records are created. Try to discover the pattern and investigate the code from there.0
-
Thanx for the suggestion. I have checked the code there is no commit statement has been used in the codeunit.
Now we have modified the code as:
"Posted Br.TransferHeader".INIT;
"Posted Br.TransferHeader".TRANSFERFIELD("Br.TransferHeader");
"Br.TransferLine".RESET;
"Br.TransferLine".SETRANGE"Br.TransferLine".Type,"Br.TransferHeader".Type);
"Br.TransferLine".SETRANGE("Br.TransferLine"."Document No","Br.TransferHeader".No);
IF "Br.TransferLine".FIND('-') THEN BEGIN
REPEAT
"Posted Br.TransferLine".INIT;
"Posted Br.TransferLine".TRANSFERFIELDS("Br.TransferLine");
"Posted Br.TransferLine".INSERT;
"Br.TransferLine".DELETE;
UNTIL "Br.TransferLine".NEXT = 0;
END;
"Posted Br.TransferHeader".INSERT;
"Br.TransferHeader".DELETE;
Can u suggest me whether this modifid code will resolve the problem.
Thanx in AdvanceRegards,
Sujatha.N0 -
sujatharaoo wrote:"Br.TransferLine".RESET;
"Br.TransferLine".SETRANGE"Br.TransferLine".Type,"Br.TransferHeader".Type);
"Br.TransferLine".SETRANGE("Br.TransferLine"."Document No","Br.TransferHeader".No);
IF "Br.TransferLine".FIND('-') THEN BEGIN
REPEAT
"Posted Br.TransferLine".INIT;
"Posted Br.TransferLine".TRANSFERFIELDS("Br.TransferLine");
"Posted Br.TransferLine".INSERT;
"Br.TransferLine".DELETE;
UNTIL "Br.TransferLine".NEXT = 0;
END;
Doesn't delete the Rec that you use for a loop. If you are under native and you delete the actual "Br.TransferLine", then the next=0 will find no next and stop looping. so use a separate instance for deleting like:"Br.TransferLine".SETRANGE"Br.TransferLine".Type,"Br.TransferHeader".Type); "Br.TransferLine".SETRANGE("Br.TransferLine"."Document No","Br.TransferHeader".No); IF "Br.TransferLine".FIND('-') THEN BEGIN REPEAT "BrTransferLineToDelete" := "Br.TransferLine"; //or a get with the PK field values "Posted Br.TransferLine".INIT; "Posted Br.TransferLine".TRANSFERFIELDS("Br.TransferLine"); "Posted Br.TransferLine".INSERT; //"Br.TransferLine".DELETE; //this we comment out "BrTransferLineToDelete".delete; UNTIL "Br.TransferLine".NEXT = 0; END;
Do you make it right, it works too!0 -
Hi Garak,
Thanx.. Let me try out this..Regards,
Sujatha.N0 -
sujatharaoo wrote:When Concurrent users are Posting, the Posted Transfer order Shipment is also getting deleted..
Well, from a logical point of view there are only 3 possibilities, when a record is "getting deleted":
1.) In the code there is something like "Posted Br.TransferHeader".DELETE (or DELETEALL)
2.) The "Posted Br.TransferHeader" has never been inserted (as DenSter pointed out) - in your case, this would mean that there are COMMITs in the posting routines before the INSERT (to be sure that there are no commits you have to check this with the client monitor!) but in your code, the posted record is inserted before the unposted one is deleted, so if there would occur an error or a "broken transaction" during posting, the unposted record should not have been deleted, too, and could be posted again... - and, if an error occurs, the user is notified (and perhaps can remember) that something has gone wrong, when he is later ashtonished that the posted record cannot be found.
3.) One or another user deletes the record manually.
My suggestion is that you verify, that 3.) is not possible.
By the way, it is not critical to delete a looping record within the loop, because the NEXT statement (in my experience) works as if the record is still "alive".New kits on the blog: https://massivedynamicsblog.wordpress.com0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions