web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Calculate SalesLine lineAmount by code

(0) ShareShare
ReportReport
Posted on by 1,552

Hi,

I have a service to create a sales order, where i pass the Qty,SalesPrice and LineAmount.

I want to say that if Qty*SalesPrice sent to the service really equal the lineAmount sent then keep it. However, if it's wrong then i want recalculate SalesPrice based on the sent LineAmount

My question is, which is the correct method to use, salesLine.calcLineAmount() or salesLine.calcLineAmountForced() or salesLine.calcLineAmountForcedInteraction()? what's the difference?

    salesLine.SalesQty      = _reqLine.Qty();  //assume reqLine is defined
    salesLine.SalesPrice    = _reqLine.Price();
    
    real x= salesLine.calcLineAmount();
    real y = salesLine.calcLineAmountForced();
    real z = salesLine.salesLine.calcLineAmountForcedInteraction(); //this one need a parameter to be passed
    
    if(x != _reqLine.LineAmount())
    {
        salesLine.SalesPrice    = _reqLine.LineAmount()/salesLine.Qty;
    }

    
    salesLine.LineAmount    = _reqLine.LineAmount();

I have the same question (0)
  • Suggested answer
    Martin Dráb Profile Picture
    237,980 Most Valuable Professional on at

    The correct calculation includes more things than just quantity and unit price. There may be discounts, for instance.

    If you want the line amount to always match the result of calcLineAmount(), you shouldn't try to set LineAmount by yourself - you should call calcLineAmount() in both cases.

    When you call the calculation, the system checks if the line amount wasn't set manually. Overwriting it may be a bad idea. If done interactively, the system may ask the user for a decision. Or you may force the recalculation, losing the amount set manually. That's what the other methods are about.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 467 Super User 2025 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 420 Most Valuable Professional

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 241 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans