Display page no in format PageNo / TotalPage Simple trick

MtamimiiMtamimii Member Posts: 7
edited 2008-05-31 in NAV Tips & Tricks
Hi All

This small trick to print the total page number for the report.
- Form ID 80000.
- Report ID 80000 Copy of the vendor report.

run the form and check the idea. :-k


(Code has been updated check down) :wink:

Comments

  • kinekine Member Posts: 12,562
    Send the files to Luc and he will upload it to the download section...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Luc_VanDyckLuc_VanDyck Member, Moderator, Administrator Posts: 3,633
    It doesn't work correctly if you set a filter on the Vendors. As first the report is saved to XML without filters, the total pagecount is wrong on the 2nd run of the report.
    No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)
  • SavatageSavatage Member Posts: 7,142
    should it be in the download section if it's flawed?
  • Luc_VanDyckLuc_VanDyck Member, Moderator, Administrator Posts: 3,633
    Because a file is available for download in the download section, doesn't mean that it works correctly. This one I figured out quite easily, but normally I cannot test every download thoroughly.

    And isn't this what the community is all about: one has an idea, develops some code and makes it available for others, so others can submit comments & suggestions to improve the code.
    No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)
  • MtamimiiMtamimii Member Posts: 7
    check this update
    OBJECT Form 80000 GetPageNoTest
    {
      OBJECT-PROPERTIES
      {
        Date=05/31/08;
        Time=[ 8:27:29 AM];
        Modified=Yes;
        Version List=;
      }
      PROPERTIES
      {
        Width=8000;
        Height=3190;
      }
      CONTROLS
      {
        { 1000000000;CommandButton;1980;1210;2860;550;
                                                     CaptionML=ENU=Run Vendor Report;
                                                     OnPush=BEGIN
                                                              {
                                                              intFileName := 0;
    
                                                              REPEAT
                                                                 intFileName := intFileName + 1
                                                              UNTIL NOT EXISTS ( FORMAT(intFileName) + '.xml');
    
                                                              CLEAR(rptTestReport);
    
                                                              rptTestReport.SAVEASXML(FORMAT(intFileName) + '.xml');
    
                                                              intTotalPageNo :=rptTestReport.getPageNo;
    
                                                              IF ERASE( FORMAT(intFileName) + '.xml') THEN BEGIN
                                                              END;
    
                                                              CLEAR(rptTestReport);
    
                                                              rptTestReport.SetPageNo (intTotalPageNo);
                                                              }
                                                              rptTestReport.RUN;
    
                                                              CLEAR(rptTestReport);
                                                            END;
                                                             }
      }
      CODE
      {
        VAR
          rptTestReport@1000000000 : Report 80000;
          intTotalPageNo@1000000001 : Integer;
          intFileName@1000000002 : Integer;
    
        BEGIN
        END.
      }
    }
    
    OBJECT Report 80000 GetPageNoForOrder
    {
      OBJECT-PROPERTIES
      {
        Date=05/31/08;
        Time=[ 8:54:00 AM];
        Modified=Yes;
        Version List=NAVW15.00;
      }
      PROPERTIES
      {
        CaptionML=ENU=Vendor - List;
        OnPreReport=BEGIN
    
                      VendFilter := Vendor.GETFILTERS;
    
                      IF NOT bolCalcPageNo  THEN BEGIN
                         intFileName := 0;
    
                         REPEAT
                         intFileName := intFileName + 1
                         UNTIL NOT EXISTS ( FORMAT(intFileName) + '.xml');
    
                         CLEAR(rptTestReport);
                         rptTestReport.SetCalcStatus;
                         rptTestReport.SETTABLEVIEW (Vendor);
                         rptTestReport.SAVEASXML(FORMAT(intFileName) + '.xml');
    
                         intTotalPageNo :=rptTestReport.getPageNo;
    
                         IF ERASE( FORMAT(intFileName) + '.xml') THEN BEGIN
                         END;
                      END;
                    END;
    
      }
      DATAITEMS
      {
        { PROPERTIES
          {
            DataItemTable=Table23;
            OnPreDataItem=BEGIN
    
    
    
                            CurrReport.CREATETOTALS("Balance (LCY)");
                          END;
    
            OnAfterGetRecord=BEGIN
                               CALCFIELDS("Balance (LCY)");
                               FormatAddr.FormatAddr(
                                 VendAddr,Name,"Name 2",'',Address,"Address 2",
                                 City,"Post Code",County,"Country/Region Code");
                             END;
    
            ReqFilterFields=No.,Search Name,Vendor Posting Group;
          }
          SECTIONS
          {
            { PROPERTIES
              {
                SectionType=Header;
                PrintOnEveryPage=Yes;
                SectionWidth=18150;
                SectionHeight=1004;
              }
              CONTROLS
              {
                { 1   ;Label        ;0    ;0    ;7500 ;423  ;FontSize=8;
                                                             FontBold=Yes;
                                                             CaptionML=ENU=Vendor - List }
                { 2   ;TextBox      ;15000;0    ;3150 ;423  ;HorzAlign=Right;
                                                             SourceExpr=FORMAT(TODAY,0,4) }
                { 3   ;TextBox      ;0    ;423  ;7500 ;423  ;SourceExpr=COMPANYNAME }
                { 1000000000;Label  ;15928;450  ;750  ;423  ;ParentControl=1000000001 }
                { 1000000001;TextBox;16678;450  ;450  ;423  ;CaptionML=ENU=Page;
                                                             SourceExpr=CurrReport.PAGENO }
                { 1000000002;Label  ;17128;451  ;485  ;423  ;HorzAlign=Center;
                                                             VertAlign=Center;
                                                             CaptionML=ENU=/ }
                { 1000000003;TextBox;17604;451  ;450  ;423  ;CaptionML=ENU=Page;
                                                             SourceExpr=rptTestReport.getPageNo }
              }
               }
            { PROPERTIES
              {
                SectionType=Header;
                PrintOnEveryPage=Yes;
                SectionWidth=18150;
                SectionHeight=423;
              }
              CONTROLS
              {
              }
               }
            { PROPERTIES
              {
                SectionType=Header;
                PrintOnEveryPage=Yes;
                SectionWidth=18150;
                SectionHeight=450;
                OnPreSection=BEGIN
                               CurrReport.SHOWOUTPUT((CurrReport.PAGENO = 1) AND (VendFilter <> ''));
                             END;
    
              }
              CONTROLS
              {
                { 8   ;TextBox      ;0    ;0    ;18150;423  ;SourceExpr=Vendor.TABLECAPTION + ': ' + VendFilter }
              }
               }
            { PROPERTIES
              {
                SectionType=Header;
                PrintOnEveryPage=Yes;
                SectionWidth=18150;
                SectionHeight=1269;
              }
              CONTROLS
              {
                { 9   ;Label        ;0    ;0    ;1500 ;846  ;ParentControl=18;
                                                             VertAlign=Bottom;
                                                             FontBold=Yes;
                                                             MultiLine=Yes }
                { 10  ;Label        ;1650 ;0    ;4500 ;846  ;ParentControl=19;
                                                             VertAlign=Bottom;
                                                             FontBold=Yes;
                                                             MultiLine=Yes }
                { 11  ;Label        ;6300 ;0    ;1500 ;846  ;ParentControl=20;
                                                             VertAlign=Bottom;
                                                             FontBold=Yes;
                                                             MultiLine=Yes }
                { 12  ;Label        ;7950 ;0    ;1500 ;846  ;ParentControl=21;
                                                             VertAlign=Bottom;
                                                             FontBold=Yes;
                                                             MultiLine=Yes }
                { 13  ;Label        ;9600 ;0    ;1500 ;846  ;ParentControl=22;
                                                             VertAlign=Bottom;
                                                             FontBold=Yes;
                                                             MultiLine=Yes }
                { 14  ;Label        ;11250;0    ;1500 ;846  ;ParentControl=23;
                                                             VertAlign=Bottom;
                                                             FontBold=Yes;
                                                             MultiLine=Yes }
                { 15  ;Label        ;12900;0    ;1500 ;846  ;ParentControl=24;
                                                             HorzAlign=Right;
                                                             VertAlign=Bottom;
                                                             FontBold=Yes;
                                                             MultiLine=Yes }
                { 16  ;Label        ;14550;0    ;750  ;846  ;ParentControl=25;
                                                             VertAlign=Bottom;
                                                             FontBold=Yes;
                                                             MultiLine=Yes }
                { 17  ;Label        ;15450;0    ;1800 ;846  ;ParentControl=26;
                                                             HorzAlign=Right;
                                                             VertAlign=Bottom;
                                                             FontBold=Yes;
                                                             MultiLine=Yes }
              }
               }
            { PROPERTIES
              {
                SectionType=Body;
                SectionWidth=18150;
                SectionHeight=4653;
              }
              CONTROLS
              {
                { 18  ;TextBox      ;0    ;0    ;1500 ;423  ;FontBold=Yes;
                                                             SourceExpr="No." }
                { 19  ;TextBox      ;1650 ;0    ;4500 ;423  ;FontBold=Yes;
                                                             CaptionML=ENU=Name and Address;
                                                             SourceExpr=VendAddr[1] }
                { 20  ;TextBox      ;6300 ;0    ;1500 ;423  ;CaptionML=ENU=Vendor Posting Group;
                                                             SourceExpr="Vendor Posting Group" }
                { 21  ;TextBox      ;7950 ;0    ;1500 ;423  ;CaptionML=ENU=Invoice Disc. Code;
                                                             SourceExpr="Invoice Disc. Code" }
                { 22  ;TextBox      ;9600 ;0    ;1500 ;423  ;CaptionML=ENU=Payment Terms Code;
                                                             SourceExpr="Payment Terms Code" }
                { 23  ;TextBox      ;11250;0    ;1500 ;423  ;CaptionML=ENU=Payment Method;
                                                             SourceExpr="Payment Method Code" }
                { 24  ;TextBox      ;12900;0    ;1500 ;423  ;SourceExpr=Priority }
                { 25  ;TextBox      ;14550;0    ;750  ;423  ;CaptionML=ENU=Currency Code;
                                                             SourceExpr="Currency Code" }
                { 26  ;TextBox      ;15450;0    ;1800 ;423  ;SourceExpr="Balance (LCY)" }
                { 27  ;TextBox      ;1650 ;423  ;4500 ;423  ;SourceExpr=VendAddr[2] }
                { 28  ;TextBox      ;1650 ;846  ;4500 ;423  ;SourceExpr=VendAddr[3] }
                { 29  ;TextBox      ;1650 ;1269 ;4500 ;423  ;SourceExpr=VendAddr[4] }
                { 30  ;TextBox      ;1650 ;1692 ;4500 ;423  ;SourceExpr=VendAddr[5] }
                { 31  ;Label        ;1650 ;2961 ;1500 ;423  ;ParentControl=32 }
                { 32  ;TextBox      ;3300 ;2961 ;2850 ;423  ;SourceExpr=Contact }
                { 33  ;Label        ;1650 ;3384 ;1500 ;423  ;ParentControl=34 }
                { 34  ;TextBox      ;3300 ;3384 ;2850 ;423  ;SourceExpr="Phone No." }
                { 37  ;TextBox      ;1650 ;2115 ;4500 ;423  ;SourceExpr=VendAddr[6] }
                { 38  ;TextBox      ;1650 ;2538 ;4500 ;423  ;SourceExpr=VendAddr[7] }
              }
               }
            { PROPERTIES
              {
                SectionType=Footer;
                SectionWidth=18150;
                SectionHeight=476;
                OnPostSection=BEGIN
    
                                ReportTotalPage := CurrReport.PAGENO;
                              END;
    
              }
              CONTROLS
              {
                { 35  ;Label        ;0    ;0    ;2250 ;423  ;FontBold=Yes;
                                                             CaptionML=ENU=Total (LCY) }
                { 36  ;TextBox      ;2300 ;0    ;1800 ;423  ;FontBold=Yes;
                                                             SourceExpr="Balance (LCY)" }
              }
               }
          }
           }
      }
      REQUESTFORM
      {
        PROPERTIES
        {
          Width=0;
          Height=110;
          SaveValues=Yes;
        }
        CONTROLS
        {
        }
      }
      CODE
      {
        VAR
          VendFilter@1000 : Text[250];
          VendAddr@1001 : ARRAY [8] OF Text[50];
          FormatAddr@1002 : Codeunit 365;
          ReportTotalPage@1000000000 : Integer;
          rptTestReport@1000000003 : Report 80000;
          intTotalPageNo@1000000002 : Integer;
          intFileName@1000000001 : Integer;
          bolCalcPageNo@1000000004 : Boolean;
    
        PROCEDURE getPageNo@1000000002() ReturnPage : Integer;
        BEGIN
          ReturnPage :=   ReportTotalPage;
        END;
    
        PROCEDURE SetPageNo@1000000032(PageNumber@1000000000 : Integer);
        BEGIN
           ReportTotalPage := PageNumber;
        END;
    
        PROCEDURE SetCalcStatus@1000000000();
        BEGIN
                 bolCalcPageNo := TRUE;
        END;
    
        BEGIN
        END.
      }
    }
    
    
Sign In or Register to comment.