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 :
Microsoft Dynamics NAV (Archived)

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

(0) ShareShare
ReportReport
Posted on by

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

I have the same question (0)
  • Suggested answer
    Binesh Profile Picture
    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;

  • Community Member Profile Picture
    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

  • Binesh Profile Picture
    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
    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()

  • Verified answer
    Binesh Profile Picture
    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
    on at
    RE: Trying to get the data in the report from two different tables in the report

    Thanks it helped! :)

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics NAV (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans