Question Status

Verified
Kuan Yi Wu asked a question on 4 Sep 2013 1:07 AM

Hi Everyone

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.

void clicked()
{

SalesTable ss;
SalesLine newsalesLine;
SalesLineDiscount newsLineDiscount;

;
super();

newsalesLine.clear();

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();

}

Thank You.

Reply
Verified Answer
Ryuji Mita responded on 4 Sep 2013 9:28 PM

Kuan Yi,

Hi.

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.

Ryuji

Reply
Ryuji Mita responded on 4 Sep 2013 1:16 AM

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.

Regards,

Ryuji

Reply
Kuan Yi Wu responded on 4 Sep 2013 8:07 PM

Hi Ryuji

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?

Regards,

Kuan Yi

Reply
Verified Answer
Ryuji Mita responded on 4 Sep 2013 9:28 PM

Kuan Yi,

Hi.

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.

Ryuji

Reply