Skip to main content

Notifications

Microsoft Dynamics NAV (Archived)

Trying to get the data in the report from two different tables in the report

Posted on by Microsoft Employee

Hi,

I'm trying to get the two fields (Amount and Date) from each of the table by just checking if Date is blank in Table1 then fetch the record from Table2. The record from the both tables are selected using a common Primary Key.

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Trying to get the data in the report from two different tables in the report

    Thanks it helped! :)

  • Verified answer
    Binesh Profile Picture
    Binesh 7,885 on at
    RE: Trying to get the data in the report from two different tables in the report

    Hello, use below code in Cust. Ledger Entry - OnAfterGetRecord()

    Cust. Ledger Entry - OnAfterGetRecord()
    //>>Sbinesh - 09.15.17

    CLEAR(AmountVariable);

    CLEAR(DueDateVariable);
    IF "CF_Promised to pay date" = 0D THEN BEGIN
      CF_CollectionPaymentScheduleTable.RESET;
      CF_CollectionPaymentScheduleTable.SETRANGE("Customer No.","Customer No.");
      IF CF_CollectionPaymentScheduleTable.FINDFIRST THEN BEGIN
        AmountVariable := CF_CollectionPaymentScheduleTable."Payment Amount";
        DueDateVariable := CF_CollectionPaymentScheduleTable."Payment Date";
      END;
    END ELSE BEGIN
      AmountVariable := "CF_Promised to pay amount";
      DueDateVariable := "CF_Promised to pay date";
    END;
    //<<Sbinesh - 09.15.17

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Trying to get the data in the report from two different tables in the report

    Documentation()

    OnInitReport()

    OnPreReport()

    //Getting Company Details

    CompanyInfoTable.RESET;

    CompanyInfoTable.GET;

    IF CompanyInfoTable.FINDFIRST THEN BEGIN

     Companyaddress1 := CompanyInfoTable.Address;

     Companyaddress2 := CompanyInfoTable."Address 2";

     CompanyName1 := CompanyInfoTable.Name;

    END;

    //Company Details END

    OnPostReport()

    Customer - OnPreDataItem()

    Customer - OnAfterGetRecord()

    Customer - OnPostDataItem()

    Cust. Ledger Entry - OnPreDataItem()

    Cust. Ledger Entry - OnAfterGetRecord()

    {Binesh Code.

    IF Table1.Date_Field = 0D THEN BEGIN

      IF Table2.GET(Table1.Primary_Key_Field) THEN BEGIN

    Table1.Date_Field := Table2.Date_Field;

      END;

    END;}

    IF "Cust. Ledger Entry".FINDFIRST THEN BEGIN

     IF "Cust. Ledger Entry"."CF_Promised to pay date" = 0D THEN BEGIN

       //REPEAT

       CF_CollectionPaymentScheduleTable.RESET;

       CF_CollectionPaymentScheduleTable.SETRANGE("Customer No.","Cust. Ledger Entry"."Customer No.");

       IF CF_CollectionPaymentScheduleTable.FINDFIRST THEN BEGIN

           AmountVariable := CF_CollectionPaymentScheduleTable."Payment Amount";

           DueDateVariable := CF_CollectionPaymentScheduleTable."Payment Date";

           //CurrReport.BREAK;

       END;

       //UNTIL CF_CollectionPaymentScheduleTable.NEXT=0;

     END

     {ELSE BEGIN

       AmountVariable := "Cust. Ledger Entry"."CF_Promised to pay amount";

       DueDateVariable := "Cust. Ledger Entry"."CF_Promised to pay date";

     END;}

    END;

    Cust. Ledger Entry - OnPostDataItem()

    CF_CollectionPaymentSchedule - OnPreDataItem()

    CF_CollectionPaymentSchedule - OnAfterGetRecord()

    CF_CollectionPaymentSchedule - OnPostDataItem()

  • Binesh Profile Picture
    Binesh 7,885 on at
    RE: Trying to get the data in the report from two different tables in the report

    Hello,

    For better result post your original code,

    In your posted code you are not getting Table2, So without seeing how could we give you solution.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Trying to get the data in the report from two different tables in the report

    This code is fetching only one entry of the Table1.

    Is it because I'm using a variable of type date instead of Table1.Datefield.

    I've even tried using REPEAT UNTIL after the second IF statement

    The indentations is as follows

    Customer

    |_DateVariable

    |_Table1(Field =  Customer.No)

    |_Table2(Field = Customer.No)

    The condition is IF Table1.Date = 0D THEN DateVariable := Table2.Date

    ELSE DateVariable := Table1.Date

  • Suggested answer
    Binesh Profile Picture
    Binesh 7,885 on at
    RE: Trying to get the data in the report from two different tables in the report

    Hello,

    Design your report for data Item Table1

    and write a code in 

    Table1 - OnAfterGetRecord()
    IF Table1.Date_Field = 0D THEN BEGIN
       IF Table2.GET(Table1.Primary_Key_Field) THEN BEGIN

    Table1.Date_Field := Table2.Date_Field;

       END;

    END;

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans