Sales Line-Header INSERT

oioi007
Member Posts: 41
Hi guys
I need a little help/advice
I'm writing code on button which will create Sales Orders from another Test.Table
I have a problem when I want to insert lines in same Sales order. for example
===
No. Item Customer
1 100 100
2 200 200
In this situation button creates 2 sales order
but i want to make like this:
No. Item Customer
1 100 100
2 200 200
3 300 200
1 sales order with customer 100, and 1 with 200, two item in Sales line
(200,300)
Thanks
I need a little help/advice
I'm writing code on button which will create Sales Orders from another Test.Table
I have a problem when I want to insert lines in same Sales order. for example
===
No. Item Customer
1 100 100
2 200 200
In this situation button creates 2 sales order
but i want to make like this:
No. Item Customer
1 100 100
2 200 200
3 300 200
1 sales order with customer 100, and 1 with 200, two item in Sales line
(200,300)
Thanks
0
Comments
-
And where is your problem :?:
Is your source #-o :?:Do you make it right, it works too!0 -
So sort your table by Customer number, and only create a new header when the customer number changes while you're looping through the records.0
-
DenSter wrote:So sort your table by Customer number, and only create a new header when the customer number changes while you're looping through the records.
Please write an example code O:) and what u mean sort table by customer? if you mean Keys, it's enabled on No. and Customer0 -
zeig mal deinen Quellcode, was du bis jetzt hast.
Let us view your sourcecode, what you have "designed".
Than we can halp youDo you make it right, it works too!0 -
garak wrote:zeig mal deinen Quellcode, was du bis jetzt hast.
Let us view your sourcecode, what you have "designed".
Than we can halp you
SalesHeader.SETRANGE("No.");
IF Test.FINDSET THEN
REPEAT
CLEAR(SalesHeader);
NoSeries:='S-ORD-1';
SalesHeader."No." := NoSeriesMgt.GetNextNo(NoSeries,0D,FALSE);
SalesHeader."Sell-to Customer No." :=Test."Sell-to Customer" ;
Order := 1;
SalesHeader.VALIDATE(SalesHeader."Sell-to Customer No.", Test."Sell-to Customer");
SalesHeader."Document Type" := Order;
SalesHeader.INSERT;
CLEAR(SalesLine);
SalesLine."Document Type" := Order;
// SalesLine."Document No." :=SalesHeader."No."; ?
Type :=2;
SalesLine.Type := Type;
SalesLine.VALIDATE(SalesLine.Type);
SalesLine."No." := Test.Item;
SalesLine.INSERT
UNTIL Test.NEXT =0;
that's what've designed:) now help me0 -
garak wrote:zeig mal deinen Quellcode, was du bis jetzt hast.
Let us view your sourcecode, what you have "designed".
Than we can halp you
SalesHeader.SETRANGE("No.");
IF Test.FINDSET THEN
REPEAT
CLEAR(SalesHeader);
NoSeries:='S-ORD-1';
SalesHeader."No." := NoSeriesMgt.GetNextNo(NoSeries,0D,FALSE);
SalesHeader."Sell-to Customer No." :=Test."Sell-to Customer" ;
Order := 1;
SalesHeader.VALIDATE(SalesHeader."Sell-to Customer No.", Test."Sell-to Customer");
SalesHeader."Document Type" := Order;
SalesHeader.INSERT;
CLEAR(SalesLine);
SalesLine."Document Type" := Order;
// SalesLine."Document No." :=SalesHeader."No."; ?
Type :=2;
SalesLine.Type := Type;
SalesLine.VALIDATE(SalesLine.Type);
SalesLine."No." := Test.Item;
SalesLine.INSERT
UNTIL Test.NEXT =0;
that's what've designed:) now help me0 -
Or check the carry out action message tool on the purchase requisition worksheet. It is quite similar to your request and creates Purchase orders.
Report 493, CU 333.
That's how I learn...See how standard NAV work...0 -
oh your source ](*,)
first you get 3 Orders, because you create a order in your loop. so every entry in your loop creates a new order.
so, here a "fast" solutionclear(xCustNo); TEst.setcurrentkey("Sell-to Customer"); IF Test.FINDSET(false,false) THEN begin REPEAT if (xCustNo <> Test."Sell-to Customer") and (Test."Sell-to Customer" <> '') then begin SalesHeader.init; SalesHeader."No." := ''; SalesHeader.insert(true); //get No. Series automatic, if you need your own no series, use your code ('S-ORD-1') SalesHeader.validate("Sell-to Customer No.",Test."Sell-to Customer"); ... other Fields validate(); SalesHeader.modify; end; xCustNo := Test."Sell-to Customer"; if (Test.Item <> '') then begin SalesLine.init; SalesLine."Document Type" := SalesLine."Document Type"::Order; SalesLine."Document No." := SalesHeader."No."; SalesLine.validate(Type,SalesLine.Type::Item); SalesLine.validate("No.",Test.Item); SalesLine.insert; end; until Test.next = 0; end;
And, please visit a training ;-)Do you make it right, it works too!0 -
thanks garak, im newbie! sorries0 -
garak wrote:oh your source ](*,)
first you get 3 Orders, because you create a order in your loop. so every entry in your loop creates a new order.
so, here a "fast" solutionclear(xCustNo); TEst.setcurrentkey("Sell-to Customer"); IF Test.FINDSET(false,false) THEN begin REPEAT if (xCustNo <> Test."Sell-to Customer") and (Test."Sell-to Customer" <> '') then begin SalesHeader.init; SalesHeader."No." := ''; SalesHeader.insert(true); //get No. Series automatic, if you need your own no series, use your code ('S-ORD-1') SalesHeader.validate("Sell-to Customer No.",Test."Sell-to Customer"); ... other Fields validate(); SalesHeader.modify; end; xCustNo := Test."Sell-to Customer"; if (Test.Item <> '') then begin SalesLine.init; SalesLine."Document Type" := SalesLine."Document Type"::Order; SalesLine."Document No." := SalesHeader."No."; SalesLine.validate(Type,SalesLine.Type::Item); SalesLine.validate("No.",Test.Item); SalesLine.insert; end; until Test.next = 0; end;
And, please visit a training ;-)CLEAR(xCustNo); Test.SETCURRENTKEY(Line,"Sell-to Customer"); IF Test.FINDSET(FALSE,FALSE) THEN BEGIN REPEAT IF (xCustNo <> Test."Sell-to Customer") AND (Test."Sell-to Customer" <> '') THEN BEGIN SalesHeader.INIT; NoSeries:='S-ORD-1'; SalesHeader."No." := NoSeriesMgt.GetNextNo(NoSeries,0D,FALSE); SalesHeader.INSERT(TRUE); SalesHeader.VALIDATE("Sell-to Customer No.",Test."Sell-to Customer"); END; xCustNo := Test."Sell-to Customer"; IF (Test.Item <> '') THEN BEGIN SalesLine.INIT; SalesLine."Document Type" := SalesLine."Document Type"::Order; SalesLine."Document No." := SalesHeader."No."; ; SalesLine.VALIDATE(Type,SalesLine.Type::Item); SalesLine.VALIDATE("No.",Test.Item); SalesLine.INSERT; END; UNTIL Test.NEXT = 0; END;
not workingon push it says "The Sales Header does not exist; Doc-type Ordder , No-1012
0 -
On which Line of code this message occurs?
(check with debugger)
Try with Garaks code for use of get standard No. maybe?0 -
Test.SETCURRENTKEY(Line,"Sell-to Customer"); IF Test.FINDSET(FALSE,FALSE) THEN BEGIN REPEAT IF (xCustNo <> Test."Sell-to Customer") AND (Test."Sell-to Customer" <> '') THEN BEGIN SalesHeader.INIT; SalesHeader."Document Type" := SalesHeader."Document Type"::Order; NoSeries:='S-ORD-1'; SalesHeader."No." := NoSeriesMgt.GetNextNo(NoSeries,0D,FALSE); SalesHeader."Sell-to Customer No." :=Test."Sell-to Customer" ; SalesLine.INIT; SalesLine."Document Type" := SalesLine."Document Type"::Order; SalesLine."Document No." := SalesHeader."No."; SalesLine.Type := SalesLine.Type::Item; SalesLine."No." :=Test.Item; SalesHeader.INSERT(TRUE); SalesHeader.MODIFY; SalesLine.INSERT; END; xCustNo := Test."Sell-to Customer"; UNTIL Test.NEXT =0; xCustNo :=''; END;
This code creates sales headers right,also inserts sales line on each header, BUT it it only inserts the first item of the same Sell-to Customer
I tried second routine repeat until on sales line, but I cant get work it. what should I do?0 -
Sales Line has Field Line No in its key, so on the repeat you should do LineNo := LineNo +10000 or something like that...just guessing...0
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