Accessing data between Sales Header and Sales Line

Short Version: I want to take a value on the Sales Header Form and multiply it by the highest “Unit Price” value in the Sales Line Form. (and there’s a reason I can’t just calculate the value of the sales lines).

Long Version (the Why): Due to the nature of my company (Aquaculture) we don’t always know how many boxes of fish will be produced in various scenarios, we’ve modded Nav to automatically allocate boxes to orders, etc and set the correct no of boxes on a line, if it’s over or under allocated. As part of this quantities and weights are set to 99 or 999, and adjusted automatically when the order is shipped and invoiced.

Quite often a customer will want 100 boxes of fish, they’re not to bothered if 80 boxes are say 6-7kg fish and the other 20 are 5-6kg, they just want 100 boxes. As part of our complex allocation we can specify a “Target Quantity” in the header for an order and it will allocate however many boxes of each item specified on the Sales Line so there is a total of 100 boxes allocated across the sales Lines.

Now… for credit checking we want to see the highest potential value for an order and display it on the Sales Header form, so what I want to do is take the highest “Unit Price” from the Sales Line and multiply it by the “Target Quantity” in the Sales Header

I’m used to C# and SQL, getting my head around C/AL has been a bit more confusing than I thought. I’ve read some of the posts on Main Forms and Sub Forms and I’m not quite joining the dots. What’s confusing me is how to go about connecting to the Sales Line form from the Sales Header form and selecting the unit price for each record in the Sales Line.

Does anyone have any good examples of code to make this happen, or to access more than one value on a subform with lines, I’ve had a play around, read other code (Which previously I edited successfully), and it’s doing my head in. Any advice suggestions of good tutorials that would go into the level of detail I require to code this?

Thanks

Dougie

Ha ha… got it sussed.

I created a textbox on the Sales Header Form and set it’s source expression to maxOrderTotal, then created two funcs/procs .

So I set up my variables, grab the Order No from the Sales Header Form and pass that into the procedure to work out the highest unit price.

CalcOrderTotal()
orderNo := “No.”;
unitPrice := 0;
maxOrderTotal := 0;
targetBoxes := 0;
targetBoxes := “Target Case Quantity”;
GetHighestUnitPrice(orderNo);
maxOrderTotal := unitPrice * targetBoxes;

GetHighestUnitPrice(orderNo : Text[30])
// SSC.602.002 14.06.13 DB
recSalesLine.RESET;
recSalesLine.SETCURRENTKEY(“Document No.”);
recSalesLine.SETFILTER(“Document No.”,orderNo);

IF recSalesLine.FINDSET(FALSE,FALSE) THEN BEGIN
REPEAT unitPricetemp := recSalesLine.“Unit Price”;
IF unitPricetemp > unitPrice THEN BEGIN
unitPrice := unitPricetemp;
END;
UNTIL recSalesLine.NEXT = 0;
END;

First thing noticed is you didnt put a filter on Document Type