Welcome! Log In Create A New Profile

Advanced

Printing/sending invoices with correct line sequence

Posted by Mike James 
Printing/sending invoices with correct line sequence
March 19, 2026 11:52PM
I generate invoice as PDFs or files of various types, eg XML, CSV. I had trouble retaining the original line sequence as per the source transaction.

Typically I scan a data source of invoice headers, and within the scan I filter another data source for all the invoice lines for that invoice, then scan those lines to generate the output:

FOR EACH <invoice header data source>
- Using HFilter, filter the invoice lines data source for that invoice (ordered by invoice and linenumber)
- FOR EACH <invoice lines data source>
- - Print the invoice report or create the output file

I tried 3 different ways to filter the invoice lines data:

1. FOR...EACH <invoice lines data source> - did not return the correct set of data, even though a display of the data source in the debugger showed the correct set of lines.

2. WHILE HOut(<invoice lines data source>) - correct invoice set but the lines were in random order

3. FOR EACH <invoice lines data source> where "saleid = '" + <invoice number data source>.saleid + "'" ON LineNumber

#3 worked correctly. The "where clause" created the correct subset of data, and "ON linenumber" retained the correct line sequence.

See [doc.windev.com].

This may be well known but not to me. Shared for anyone who can benefit!
Re: Printing/sending invoices with correct line sequence
April 30, 2026 02:19AM
Option 3 worked in development but not in production. Error: <fieldname> unknown. A small change fixed it:

"ON LineNumber" (a field name from the table/data source) replaced by "ON sFieldName" (a string containing the fieldname).

It's not the first time we've had to make a similar change.
Al
Re: Printing/sending invoices with correct line sequence
April 30, 2026 02:32AM
Hello Mike,

Over the years I have found Windev functions that work perfectly and those that don't as I am sure you have.
One function that randomly causes issues for me is the For Each construct, especially if you do some process inside the loop so now I never use it.

For an invoice, I load all the line records into a memory table with an incrementing numeric counter field, then sort the table on the counter field and use it to supply the body section of the invoice report.

Regards
Al
Re: Printing/sending invoices with correct line sequence
May 02, 2026 12:23AM
Thanks for your comments Al, much appreciated. Totally agree with all of it, especially your first sentence!
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: