//-SOURCE DOCUMENT = "Purchase Order" "Source Document"::"Purchase Order": BEGIN PurchInvLine.SETRANGE("OF00 Purch. Order No.","Entry No."); //(*) PurchInvLine.setrange("posting date","last invoice date"); //(*) PurchInvLine.setrange(type,purchinvline.type::Item); //(*) PurchInvLine.setrange("no.","item no."); //(*) if PurchInvLine.findset(false,false) then begin TBTempPurchInvLine."OF00 Purch. Order No." := PurchInvLine."OF00 Purch. Order No."; TBTempPurchInvLine."posting date" := PurchInvLine."posting date"; TBTempPurchInvLine.type := PurchInvLine.type; TBTempPurchInvLine."no." := PurchInvLine."no."; repeat TBTempPurchInvLine."document no." := PurchInvLine."document no."; if TBTempPurchInvLine.insert then begin //Means that this (*) group of lines haven't been analyzed yet tbpurchinvlinetoloop.copyfilters(purchinvline); tbpurchinvlinetoloop.setrange("document no.",purchinvline); tbpurchinvlinetoloop.findset(false,false); repeat [Some code] until tbpurchinvlinetoloop.next = 0; end; UNTIL PurchInvLine.NEXT = 0; end; END; //+SOURCE DOCUMENT = "Purchase Order"
Answers
I'm not getting the purpose of your code. Why are you looping through the same invoice lines in two different loops? First you loop through PurchInvLine, and then if certain conditions are met, you set the same filters on tbpurchinvlinetoloop, both if which look like they are Purchase Invoice Lines.
RIS Plus, LLC
MVP - Business Apps
anyway,after the first set of filters, let's say we have these records (i filter order no = 1)
docNo OrdNo quantity
a 1 12
a 1 13
b 1 1
b 1 5
c 1 6
c 1 66
this is the [Some Code] i wrote in the previous post i have to group the records in order to have in totalinvoicedqty the sum of "a" document quantity (25) and then run a function. Obviously, i need to do this only one time per document, so i use "if insert" in order to insert only one line for the (*) fields if the "if insert" returns false, then it means that i already processed the document.
It's a bit intricated (does this word exists?), i know...
"Never memorize what you can easily find in a book".....Or Mibuso
My Blog
Apart from the fact that you could do sumindexfields for totals (which is much easier to do), it's not that hard to code for it. Sort the lines by the order number (you might have to create a key for it), so you only need one loop. Instead of the temp record variable, have a variable of the same type as the order number. Then it's a straightforward loop, something like this: It still doesn't make sense to me though. If you filter it by one value of the order number, it's never going to change. Perhaps you are not posting all the code, so in that case, substitute my control variable with the one that does change on your project and see if that does it.
RIS Plus, LLC
MVP - Business Apps
yes, "document no." is the one that changes, not OF00, sorry but i didn't specify it (document no. is a primary key field of purchase line and I don't set the other pk fields, so "if insert" instruction will return false unless the document no. changes)
anyway, your code is simpler, (i used your method in the past, why didn't i think about it? ](*,) ](*,) ](*,)
thanks a lot
"Never memorize what you can easily find in a book".....Or Mibuso
My Blog
RIS Plus, LLC
MVP - Business Apps