Sales Order Line: auto populate new lines

I am having problems creating new Sales Lines from the Sales Order form. There are Items that when they are ordered must have another item ordered as well. Example: Item #1 = peanuts, Item #2 = Bag/Sack. If 50 pounds of peanuts are ordered then they must also include one Bag/Sack in the order as well. I have a table holds the item relations. From the OnValidate trigger of the SalesLine.“No.” field of the form, I can check to see if a relation exists for the Item. If a relation exists I add a new sales line for the related item. This is where the problem occurs. I am getting a error as if I am inserting a duplicate record. It is almost as if the insert is being run twice. I can run a function that creates the new line from a button but I cannot get it to work from the OnValidate of the textbox. If anyone has any ideas, they would be greatly appreciated. Keith Reichert

Well, one way to solve your problem is to sell the 50lb bag of peanuts as a Bill of Materials. Of course that means you’d have to set up two separate inventory items— one regular item for the 50 pounds of peanuts and a BOM for the 50 lbs of peanuts in the sack. I assume that your customer failed to mention during the initial implementation that nuts are always sold in sacks, which means that many thousands of sacks of peanuts have been recorded separately from many thousands of 50 lb piles of peanuts. I also assume that tracking usage of BOTH items separately is THE key thing that this business is worried about and they will be VERY worried about tracking these sales. I would hasten to assure them that the elements of the BOMs CAN be tracked individually… --Tim Horrigan Tim.Horrigan@emsolution.com ------- Tim Horrigan

Keith, I had to do exactly the same in an earlier project. I assume it’s quite tricky but it can be done: 1) On Table 37 I have a function “InsertBags” which generates the additional line for the bags and connects this line to the peanuts-line. 2) on Form 46 I call “InsertBags” OnAfterValidate of the Quantity field (I must know how many peanuts are being ordered in order to determin the number of bags needed!) It is mandatory that at the moment you “Insert the Bags” the original line (Peanuts) has been inserted and has a valid LineNo. otherwise you will not be able to connect the two lines → If you delete the sales-line with the peanuts you also want to get rid of the bags. Therefore make sure, you DID NOT set the “DelayedInsert” property on the salesline subform (Form 46)! Marcus Fabian

It seems that from your code you’re trying to assign to a line two times the same number. Sales lines when inserted on the form are given automatically a line number by it (automatically ON THE FORM), so, if you insert a line by code, you’ll have to give a number to it too… a simple and effective way is with the following code: (sending pseudocode as i’m not using international version and i don’t know exactly the tables names used on it ). saleslineAux Sales Line; salesLineAux.RESET; salesLineAux.SETRANGE(,salesLine.); salesLineAux.SETRANGE (,salesline.salesheadernumber); salesLineAux.FIND(’+’); salesLine. := salesLineAux.+10000; Regards, Alfonso Pertierra

Keith Alfonso is quite right, you need to save the Current Sales line record, then Insert your related line. have a look at Navisions code for inserting extended text on the Sales Line for the method to retrieve your next line number and Inserting a new record. Mr David Cox MindSource (UK) Limited Navision Solutions Partner Email: david@mindsource.co.uk Web: www.mindsource.co.uk