Quantcast
Channel: Dynamics 365 Business Central/NAV User Group
Viewing all articles
Browse latest Browse all 11285

Forum Post: RE: Check Order Date vs Posting Date on Warehouse Shipment

$
0
0
Hi Dinhson, First time I've seen this one. You can't have two repeat loops in one like this. If you want to loop them, then you can do it inside with REPEAT a.findset REPEAT b.findset do-something; until b.next=0; until a.next=0 ; but that always ends up giving less readable code. And that's not the only problem. So rather than trying to tell you what was wrong, then I would do it like this: LOCAL PROCEDURE CheckSalesOrdersWarehousePostingDate() // Local vars: SalesHeader WITH SalesHeader DO BEGIN SETRANGE("Document Type","Document Type"::Order); IF SalesHeader.ISEMPTY THEN EXIT; REPEAT CheckWarehousePostingDate(SalesHeader); UNTIL WarehouseLine.NEXT = 0; END; LOCAL PROCEDURE CheckWarehousePostingDate(SalesHeader : Record "Sales Header") // Local vars: WarehouseLine WITH WarehouseShipmentLine DO BEGIN SETRANGE("Source Type", SalesHeader."Document Type"); SETRANGE("Source No.",SalesHeader."No."); IF ISEMPTY THEN EXIT; REPEAT IF "Shipment Date" <> SalesHeader."Order Date" THEN ERROR('Order Date <> Shipment Date') UNTIL NEXT = 0; END; Two separate functions, with each their task. WITH a DO BEGIN gives you a much cleaner code. Put the functions in a codeunit, not directly in a page or table. I have seen "issues" when used there, due to the global Rec var that may conflict with your with statement. Also no need for RESET's inside a function, as long as the record is only defined as a local var. Same thing can happen if you have both a global var and a local var with the same name.

Viewing all articles
Browse latest Browse all 11285

Trending Articles