Help with a code on Codeunit 82
DarkHorse
Member Posts: 389
Dear folks, I posted this a few days ago but the situation has changed. I post my problem actually.
I've created a report that shows information of an item. This report prints automatically when you are in sales ordes and push Register+Print. For it I put on Codeunit 82 Sales Post+Print the following code:
saleslines is Sales Line table
RptNumserie is the report
serial field is a flowfiled (from Item table)
from saleslines table and SERIAL is an information from that field
When I register a sales order that has an item that has the serial field as SERIAL the report prints automatically and it doesn't prints is this field is different than SERIAL. It runs well.
But my problem is that seems doesn't go over the sales line table, because if I put first an item that hasn't the information SERIAL and after an item that yes it has, the report doesn't prints, it seems go over only the first line form the sales order. How can I do go over all the lines?, I've put a "find" and an "until" but it seems don't work.
Thanks in advance for help.
I've created a report that shows information of an item. This report prints automatically when you are in sales ordes and push Register+Print. For it I put on Codeunit 82 Sales Post+Print the following code:
salesline.RESET;
salesline.SETRANGE("Document Type", SalesHeader."Document Type");
salesline.SETRANGE("Document No.", SalesHeader."No.");
salesline.SETRANGE("Sell-to Customer No.", SalesHeader."Sell-to Customer No.");
IF salesline.FIND('-') THEN BEGIN
salesline.CALCFIELDS(serial);
IF salesline.serial='SERIE' THEN REPEAT
RptNumserie.SETTABLEVIEW(SalesShptHeader) ;
RptNumserie.USEREQUESTFORM := FALSE;
RptNumserie.RUNMODAL ;
CLEAR(RptNumserie) ;
UNTIL salesline.NEXT=0;
END;
saleslines is Sales Line table
RptNumserie is the report
serial field is a flowfiled (from Item table)
from saleslines table and SERIAL is an information from that field
When I register a sales order that has an item that has the serial field as SERIAL the report prints automatically and it doesn't prints is this field is different than SERIAL. It runs well.
But my problem is that seems doesn't go over the sales line table, because if I put first an item that hasn't the information SERIAL and after an item that yes it has, the report doesn't prints, it seems go over only the first line form the sales order. How can I do go over all the lines?, I've put a "find" and an "until" but it seems don't work.
Thanks in advance for help.
0
Comments
-
Hi DarkHorse,
Put the REPEAT statement before the CALCFIELDS 8)
Albert0 -
I think it may work

salesline.RESET; salesline.SETRANGE("Document Type", SalesHeader."Document Type"); salesline.SETRANGE("Document No.", SalesHeader."No."); salesline.SETRANGE("Sell-to Customer No.", SalesHeader."Sell-to Customer No."); IF salesline.FIND('-') THEN BEGIN salesline.CALCFIELDS(serial); Repeat IF salesline.serial='SERIE' THEN begin RptNumserie.SETTABLEVIEW(SalesShptHeader) ; RptNumserie.USEREQUESTFORM := FALSE; RptNumserie.RUNMODAL ; CLEAR(RptNumserie) ; end; UNTIL salesline.NEXT=0; END;
0 -
i see a possible problem with your code though :It will print the same report for each line that has "SERIE" in it, so if there are 2 lines with that value, it will print twice. Also, if your sales order contains a line with the value "SERIE" that has been shipped in ANOTHER shipment, it will still print that one.dayakar wrote:I think it may work
salesline.RESET; salesline.SETRANGE("Document Type", SalesHeader."Document Type"); salesline.SETRANGE("Document No.", SalesHeader."No."); salesline.SETRANGE("Sell-to Customer No.", SalesHeader."Sell-to Customer No."); IF salesline.FIND('-') THEN BEGIN salesline.CALCFIELDS(serial); Repeat IF salesline.serial='SERIE' THEN begin RptNumserie.SETTABLEVIEW(SalesShptHeader) ; RptNumserie.USEREQUESTFORM := FALSE; RptNumserie.RUNMODAL ; CLEAR(RptNumserie) ; end; UNTIL salesline.NEXT=0; END;
and i suggest to NOT use magic constants like the 'SERIE' value you have in your code. make these things a setting somewhere in a setup table, because these things tend to change over time.0 -
Thanks everybody for reply, It works!!! =D> , the code that dayakar posted, and put REPEAT before the calcfields as Albertvh posted. This is the final code:
salesline.RESET; salesline.SETRANGE("Document Type", SalesHeader."Document Type"); salesline.SETRANGE("Document No.", SalesHeader."No."); salesline.SETRANGE("Sell-to Customer No.", SalesHeader."Sell-to Customer No."); IF salesline.FIND('-') THEN BEGIN REPEAT salesline.CALCFIELDS(serial); IF salesline.serial='SERIE' THEN BEGIN RptNumserie.SETTABLEVIEW(SalesShptHeader) ; RptNumserie.USEREQUESTFORM := FALSE; RptNumserie.RUNMODAL ; CLEAR(RptNumserie) ; END; UNTIL salesline.NEXT=0; END;
But, also, as MBerger said, it prints 2 times if there are two lines. Is there any way to solve it? :roll: .
Thanks everybody for help and time.0 -
CLEAR(booleanPrint);
IF salesline.FIND('-') THEN BEGIN
REPEAT
salesline.CALCFIELDS(serial);
IF salesline.serial='SERIE' THEN BEGIN
booleanPrint := TRUE;
UNTIL
(salesline.NEXT = 0) OR (booleanPrint = TRUE);
END;
IF booleanPrint THEN BEGIN
RptNumserie.SETTABLEVIEW(SalesShptHeader) ;
RptNumserie.USEREQUESTFORM := FALSE;
RptNumserie.RUNMODAL ;
CLEAR(RptNumserie) ;
END;0 -
why not just filter on the flowfield ? i know you shouldn't do that when the other filter give you a large resultset, but in this case it's very viable.
salesline.RESET; salesline.SETRANGE("Document Type", SalesHeader."Document Type"); salesline.SETRANGE("Document No.", SalesHeader."No."); salesline.SETRANGE("Sell-to Customer No.", SalesHeader."Sell-to Customer No."); Salesline.SETRANGE(Serial,'SERIE') ; if not SalesLine.IsEmpty then begin RptNumserie.SETTABLEVIEW(SalesShptHeader) ; RptNumserie.USEREQUESTFORM := FALSE; RptNumserie.RUNMODAL ; CLEAR(RptNumserie) ; end ;0 -
Yes!!!, it works. You're a real genious. Thanks everybody for your help. You help me a lot everyone of you.
Thanks again.0
Categories
- All Categories
- 75 General
- 75 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K 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
- 611 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 253 Dynamics CRM
- 103 Dynamics GP
- 6 Dynamics SL
- 1.5K Other
- 991 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 28 Design Patterns (General & Best Practices)
- Architectural Patterns
- 9 Design Patterns
- 4 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1K General Chat
- 1.6K Website
- 77 Testing
- 1.2K Download section
- 23 How Tos section
- 249 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions