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

Announcements

No record found.

News and Announcements icon
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
    238,745 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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

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

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 545 Super User 2026 Season 1

#2
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 408

#3
Adis Profile Picture

Adis 267 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans