How to use code to give discount?

Hi

I am trying to write a dicount module in AX.

how can i add discount percent or discount amt to line via code?

because i can’t direct assign value to discAmount field.
any suggestion can give me?

SalesTable ss;

DialogButton diagBut;

str strMessage;

str strTitle;

SalesLine newsalesLine;

SalesLineDiscount newsLineDiscount;

;

super();

strMessage = SalesTable.SalesId; //“The No button should have initial focus.”;

strTitle = “Title”;

diagBut = Box::yesNoCancel(

strMessage,

DialogButton::No, // Initial focus is on the No button.

strTitle);

newsalesLine.clear();

newsalesLine.SalesId = SalesTable.SalesId;

newsalesLine.ItemId = “TEST02”;

newsalesLine.QtyOrdered = 10;

newsalesLine.PriceUnit = 20;

//newsalesLine.discAmount = 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();

Do it exactly as you would do that manually. Line-level discount can be set in Discount (LineDisc) and Discount percent (LinePercent) fields.

Thank you.

sorry for this question.