Is there a more optimal way to do this

markcle
Member Posts: 65
Hi All
I'm writing my first extension that we'll use in productions. basically, I need to set to clear the qty to ship on sales lines, but for a blanket sales order, I need to go and find all the sales orders linked the blanket line and sum up the Qty on sales orders.
I tried with calcsums, but it complained about not being able to convert from boolean to int (or something along those lines), even though I was useing ReleaseSalesLines.CALCSUMS(Quantity)
I ended up looping through all the linked sales lines. Doesn't seem optimal to me (see about 90% of way down where is says "// Iterate over all sales orders and find the total qty on sales orders (Qty Ordered: Don't care if it's shipped)"
Thanks
Mark
I'm writing my first extension that we'll use in productions. basically, I need to set to clear the qty to ship on sales lines, but for a blanket sales order, I need to go and find all the sales orders linked the blanket line and sum up the Qty on sales orders.
I tried with calcsums, but it complained about not being able to convert from boolean to int (or something along those lines), even though I was useing ReleaseSalesLines.CALCSUMS(Quantity)
I ended up looping through all the linked sales lines. Doesn't seem optimal to me (see about 90% of way down where is says "// Iterate over all sales orders and find the total qty on sales orders (Qty Ordered: Don't care if it's shipped)"
codeunit 50001 SalesLineOperarions { trigger OnRun() begin end; procedure UpdateLines(DocNo: Text; DocType: Option; Zero: Boolean) var // Local var SalesLine: record "Sales Line"; ReleasesSalesLine: record "Sales Line"; BlanketReleaseQty: Integer; begin //Message('Updating Lines for Order no: %1, Doc Type: %2, Zero: %3', DocNo, DocType, Zero); // Loop thruugh all lines for this DocNo and Type where line is an item and Qty to ship is <> 0 SalesLine.SETRANGE("Document Type", DocType); SalesLine.SETRANGE("Document No.", DocNo); SalesLine.SETRANGE(Type, SalesLine.Type::Item); if Zero = true then begin SalesLine.SETFILTER(Quantity, '<>0'); end; IF SalesLine.FINDSET(TRUE) THEN REPEAT // Regular Orders // Validate record if (Zero = true) then // Message('Line: %1, Qty: %2, New Qty to Ship, %3', SalesLine."Line No.", SalesLine."Quantity", 0); SalesLine.VALIDATE("Qty. to Ship", 0) else // Message('Line: %1, Qty: %2, Qty Shipp::ed, %3, Qty Left: %4', SalesLine."Line No.", SalesLine."Quantity", SalesLine."Quantity Shipped", SalesLine."Quantity" - SalesLine."Quantity Shipped"); if (DocType = 1) then // Sales Order SalesLine.VALIDATE("Qty. to Ship", SalesLine."Quantity" - SalesLine."Quantity Shipped") else // Blanket begin // If it's a blanket find regular sales lines where Line.BlanketOrderNo = DocNo and line.BlanketLineNo = LineNo ReleasesSalesLine.SETRANGE("Document Type", 1); ReleasesSalesLine.SETRANGE("Blanket Order No.", DocNo); ReleasesSalesLine.SETRANGE("Blanket Order Line No.", SalesLine."Line No."); ReleasesSalesLine.SETRANGE(Type, SalesLine.Type::Item); BlanketReleaseQty := 0; // Iterate over all sales orders and find the total qty on sales orders (Qty Ordered: Don't care if it's shipped) IF ReleasesSalesLine.FINDSET(TRUE) THEN REPEAT BlanketReleaseQty := BlanketReleaseQty + ReleasesSalesLine.Quantity UNTIL ReleasesSalesLine.NEXT = 0; SalesLine.VALIDATE("Qty. to Ship", SalesLine."Quantity" - BlanketReleaseQty); end; // execute the OnModify() trigger SalesLine.MODIFY(TRUE); UNTIL SalesLine.NEXT = 0; end;
Thanks
Mark
0
Answers
-
[Topic moved from 'Design Patterns (General & Best Practices)' forum to 'NAV Three Tier' forum]
Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
1. Use Quantity (Base) fields instead of Quantity to avoid different measure units
2. Try use decimal parameter (e.g. TestQty) instead of Zero - more flexible
SalesLine.SETFILTER(Quantity, '<>%1', TestQty);
SalesLine.VALIDATE("Qty. to Ship", TestQty)
3. Try to use ReleasesSalesLine.CALCSUMS(Quantity) with appropriate index change to avoid loop0
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