I am trying to create a button at sales order form which allow me to add a new sales order line when i click on it, but what i get is when i click on the button, only quantity are able to insert, the unit price and discount are not filled. My code is as below, please advice.
SalesTable ss;SalesLine newsalesLine; SalesLineDiscount newsLineDiscount;
newsalesLine.SalesId = SalesTable.SalesId; newsalesLine.ItemId = "Test02";
newsalesLine.SalesQty = 20.00; newsalesLine.SalesPrice = 30.00; newsalesLine.LineDisc = 10;
newsalesLine.createLine(NoYes::Yes, // Validate NoYes::Yes, // initFromSalesTable NoYes::Yes, // initFromInventTable NoYes::Yes, // calcInventQty NoYes::Yes, // searchMarkup NoYes::Yes); // searchPrice SalesLine_ds.research(true); SalesLine_ds.refresh();
Looking at your code, you are specifying NoYes::Yes to the searchPrice parameter in the call to newsalesLine.createLine. This means that inside the call to createLine, price/discount information is updated by looking into the settings for the item.
If you want to specify the price and discount directly, set it after the call to createLine (make sure you call Update to the DB), or setting the last parameter in the call to createLine to noYes::No will probably do the trick.
Thanks for your advice, I had tried both your suggestion and the result was as below.
1. I try to move the price and discount after createLine but nothing happen as well.
2. I try to set validate and initFromSaleTable to Yes and others to No in CreateLine, the records can be successfully insert but the SalesLine.LineAmout(Net Amount) will not automatically calculate. Do you have any idea how to get the SalesLine.LineAmout(Net Amount) calculate by using X++ function?
1. Did you call update af ter setting the price and discount?
2. call SalesLine.LineAmount = salesLine.calcLineAmountForced(); after setting the price and discount, before calling createLine. (It's what the normal code does inside the SalesLine.modifiedField method when the discount or price field is updated in the UI)
Hope this helps.