Help with a code on Codeunit 82

DarkHorseDarkHorse 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:
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.

Comments

  • AlbertvhAlbertvh Member Posts: 516
    edited 2009-03-20
    Hi DarkHorse,

    Put the REPEAT statement before the CALCFIELDS 8)

    Albert
  • dayakardayakar Member Posts: 68
    I think it may work :D
    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;
    
    

    :wink:
  • MBergerMBerger Member Posts: 413
    dayakar wrote:
    I think it may work :D
    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;
    
    

    :wink:
    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.

    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.
  • DarkHorseDarkHorse Member Posts: 389
    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.
  • canadian_baconcanadian_bacon Member Posts: 91
    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;
  • MBergerMBerger Member Posts: 413
    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 ;
    
  • DarkHorseDarkHorse Member Posts: 389
    Yes!!!, it works. You're a real genious. Thanks everybody for your help. You help me a lot everyone of you.
    Thanks again.
Sign In or Register to comment.