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

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested answer

I want to print in the report last two order amount of all customer in nav.

(1) ShareShare
ReportReport
Posted on by 133
Sales Header - OnPreDataItem()
/Sales Header/.SETCURRENTKEY(/Document Date/,/Document Type/);
/Sales Header/.SETRANGE(/Document Type/,/Sales Header/./Document Type/::Order);
/Sales Header/.CALCFIELDS(Amount);
/Sales Header/.SETFILTER(Amount,'<>0');
/Sales Header/.SETASCENDING(/Document Date/,FALSE);
  NoOfOrder:=0;
  IF OrderAmount=0 THEN 
    REPEAT
    NoOfOrder:=NoOfOrder + 1;
      IF NoOfOrder=2 THEN BEGIN
        END;
  UNTIL (/Sales Header/.NEXT=-1) OR (NoOfOrder=2);
  
I have the same question (0)
  • Suggested answer
    YUN ZHU Profile Picture
    93,996 Super User 2025 Season 2 on at
    I want to print in the report last two order amount of all customer in nav.
    Hi, what is your problem now?
    I think it is more convenient to use Query. More details: https://learn.microsoft.com/en-us/dynamics-nav/topnumberofrows-function
     
    Hope this helps.
    Thanks.
    ZHU
  • AjayPandey Profile Picture
    133 on at
    I want to print in the report last two order amount of all customer in nav.
    I want to print only last two transaction of customer 
  • AjayPandey Profile Picture
    133 on at
    I want to print in the report last two order amount of all customer in nav.
    When i run this code it cant shows first two order amount of customer , it shows the all order amount of customer in the report. can you please suggest me what can i do .
     
     
    Documentation()
    OnInitReport()
    OnPreReport()
    OnPostReport()
    Sales Header - OnPreDataItem()
    "Sales Header".SETCURRENTKEY("Document Date","Document Type");
    "Sales Header".SETRANGE("Document Type","Sales Header"."Document Type"::Order);
    "Sales Header".SETRANGE("Sell-to Customer No.",'60000');
    "Sales Header".CALCFIELDS(Amount);
    "Sales Header".SETFILTER(Amount,'<>0');
    "Sales Header".SETASCENDING("Document Date",TRUE);
      LastTransactionCount:=0;
      IF "Sales Header".FINDFIRST THEN
      REPEAT
        LastTransactionCount:=LastTransactionCount +1; 
        OrderAmount:="Sales Header".Amount;
        UNTIL (LastTransactionCount=2) OR ( "Sales Header".NEXT=0);
    Sales Header - OnAfterGetRecord()
    Sales Header - OnPostDataItem()
     

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…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,351

#2
Sumit Singh Profile Picture

Sumit Singh 2,072

#3
YUN ZHU Profile Picture

YUN ZHU 1,807 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans