Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Suggested answer

Calculate SalesLine lineAmount by code

(0) ShareShare
ReportReport
Posted on by 1,550

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

  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 230,962 Most Valuable Professional on at
    RE: Calculate SalesLine lineAmount by code

    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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,162 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,962 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans