Line Amount not calculating even after setting salesLine.LineDisc = discountValue

I’m trying to create Sales Line from code but the Line Amount keeps defaulting to => this.PriceUnit * this.SalesQty

Here is my formula:

salesLine.LineAmount = (this.PriceUnit * this.SalesQty) - this.LineDisc;

What am i doing wrong? [emoticon:17b8c36337cb4b5fa98edf5f44e18caa]

Line amount is normally calculated by the systems from other fields - it seems that the standard calculation executes after your code. Or maybe it’s updated by another customization?

Why do you want to use your calculation instead of the standard one (which is more sophisticated)? Because something in your system has broken the standard calcuLATION and you’re trying to calculate things by yourself instead of locating and fixing the actual problem?

line amount/discount calculation works fine on the standard one Martin.

I was finding it difficult creating a sales line item using the SalesLineV2 entity (no single example on the internet on how to make use of the data entity), so i had to create a custom table that mirrors the required fields in the SalesLine table and exposed it.

Writing to the SalesLine table using the data entity of the custom table works fine but the LineAmount is not calculating even when the Discount is present.

Here’s my code:

salesLine.LineDisc = this.LineDisc;
salesLine.LineAmount = salesLine.calcLineAmount();

salesLine.createLine(NoYes::Yes, // Validate
NoYes::Yes, // initFromSalesTable
NoYes::Yes, // initFromInventTable
NoYes::Yes, // calcInventQty
NoYes::Yes, // searchMarkup
NoYes::Yes);

There are several different points to address.

  • You said the standard calculation works fine and also that LineAmount is not calculating. I’m not sure how I should understand it.
  • I believe you should use the standard logic and not trying to calculate the value by yourself (because it’s much more complicated than just PriceUnit * SalesQty - LineDisc.
  • Consider calling modifiedField() after changing fields related to price, or make sure that you call similar logic. Notice the calls of setPriceDiscChangePolicy() and calcLineAmountForcedInteraction().
  • You forgot to attach a tag with your version of AX. It is a good guess that you mean SalesOrderLineV2Entity in D365FO when you talk about SalesLineV2? Maybe you should create a thread about your problem with the entity. It’s likely that there is a better approach than giving up the whole entity developed and supported by Microsoft and developing a custom solution for exactly the same purpose.

I mean this works fine when I go through the Sales Orders list page and drills down on the Sales Order and then clicks on the “Add line” on the sales line grid to add a sales line

I’m on D365 F&O, Yes I mean SalesOrderLineV2Entity.

Microsoft needs to do better with examples on how to consume these OOB data entities, it can be really really frustrating when you’re trying to call the endpoint and its not just working…