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

Announcements

News and Announcements icon
Community site session details

Community site session details

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

How to make lowest sales price item value zero of sales order lines ?

(1) ShareShare
ReportReport
Posted on by 226
I am building a scenario where i have 2 lines in sales order .The scenario is that we have to compare the price of both lines with each other. The item with the lower sales price price will be updated to sales price = "0" by code. Can anyone provide me guidance on this ???
For example these are the given lines the item with 36 sales price will be updated as zero.
I have the same question (0)
  • André Arnaud de Calavon Profile Picture
    306,640 Super User 2026 Season 2 on at
    Hi JJDunaid,
     
    What exact guidance do you need? Do you need help with coding to find the line with the lowest unit price? Is there any dependency on the quantity? What in case the line with unit price of 36 has a quantity of 500 where the line with price 240 has a quantity of 1?
    Do you need the logic to be executed automatically, e.g. upon confirming the order or do you have a button for the user to click? Please let us know with more details where and how you need help.
  • JJDunaid Profile Picture
    226 on at
    Hi André ,
    Yes, I have a trigger point from where the functionality will work on secondly,  for instance there is no scope for quantity and Yes i need logic as i'm facing issue developing one.
  • Suggested answer
    André Arnaud de Calavon Profile Picture
    306,640 Super User 2026 Season 2 on at
    Hi JJDunaid,
     
    Thanks for the clarification you can try some coding like the next example.
     
    public void setZeroPriceForLine(SalesTable _salesTable)
    {
        SalesLine    salesLine;
    
        ttsbegin;
    
        select firstonly forupdate salesLine
        order by salesLine.SalesPrice asc
        where salesLine.SalesId == _salesTable.SalesId;
    
        if (salesLine.RecId != 0)
        {
            salesLine.SalesPrice = 0;
            salesLine.ModifiedField(fieldNum(SalesLine, SalesPrice));
            salesLine.update();
        }
    
        ttscommit;
    }

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders

These are the community rock stars!

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

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 303 Super User 2026 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 264 Most Valuable Professional

#3
Anton Venter Profile Picture

Anton Venter 256 Super User 2026 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans