Help needed for looping Sales Invoice Line!

ImaspalImaspal Member Posts: 68
Hi Experts!

I have to get document numbers from a Sales Invoice Line -table (invoice numbers). I have to get numbers:
- that belong to a certain Customer,
- that consist (invoices) of certain group of Items.

These numbers I have to put for example in a String.

How can I do that? A code example would be very much awaited.

Yours,
IP

Comments

  • NagiNagi Member Posts: 151
    Hello Imaspal,

    First thing very easy;
    SalesInvLine.RESET;
    SalesInvLine.SETRANGE("Sell-to Customer No.",CustomerNo);
    //Or maybe you want to set filter on Bill-to Customer No.?
    SalesInvLine.SETRANGE(Type,Type::Item);
    SalesInvLine.SETRANGE("No.",ItemNo);
    IF SalesInvLine.FINDSET THEN
      REPEAT
        //Looping through records..
      UNTIL SalesInvLine.NEXT = 0;
    

    If all you want is to place the document nos. in a string, then just add the following code when looping through records in Sales Invoice Line;
    IF ListOfDocNos = '' THEN
      ListOfDocNos := SalesInvLine."Document No."
    ELSE IF STRLEN(ListOfDocNos + ' ' + SalesInvLine."Document No.") < MAXSTRLEN(ListOfDocNos) THEN
      ListOfDocNos += ' ' + SalesInvLine."Document No.";
    

    However, it could be that you'd want to use a temp table and then build records so that you can easily display a long list of document nos. in a report. If that's the case, then things get a little bit more complicated. You could use Comment Line as a temporary table to achieve this.

    Here's some code that I've used myself to get a list of serial nos. associated with any given item.
    ItemLedgEntryTemp.RESET;
    IF ItemLedgEntryTemp.FINDSET THEN BEGIN
      LineNo := 0;
      DoInit := TRUE;
      REPEAT
        IF (STRLEN(CommentTemp.Comment + ' ' + ItemLedgEntryTemp."Serial No.") > MAXSTRLEN(CommentTemp.Comment)) OR (DoInit) THEN BEGIN
          LineNo += 1;
          CommentTemp.INIT;
          CommentTemp."Table Name" := CommentTemp."Table Name"::Item;
          CommentTemp."No." := "Sales Shipment Line"."No.";
          CommentTemp."Line No." := LineNo;
          CommentTemp.Date := TODAY;
          CommentTemp.Comment := ItemLedgEntryTemp."Serial No.";
          CommentTemp.INSERT;
          DoInit := FALSE;
        END ELSE BEGIN
          CommentTemp.Comment += ' ' + ItemLedgEntryTemp."Serial No.";
          CommentTemp.MODIFY;
        END;
      UNTIL ItemLedgEntryTemp.NEXT = 0;
    END;
    
  • ImaspalImaspal Member Posts: 68
    Thank you for your exhaustive help. I'm very appreciated!

    Yours,
    IP
Sign In or Register to comment.