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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

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

Possible to create new API Query with 3 or more DataItems?

(0) ShareShare
ReportReport
Posted on by 35

Hi there,

Is it possible to create a new AL API Query that links 3 or more DataItems?

For example, say I want to link the tables 81 (Gen. Journal Line), 288 (Vendor Bank Account) and 23 (Vendor).

I can link two of them no problem.

query 53000 TestQuery
{
    QueryType = API;
    APIPublisher = 'Test';
    APIGroup = 'GroupName';
    APIVersion = 'v2.0';
    EntityName = 'TestQuery';
    EntitySetName = 'TestQuerys';

    elements
    {
        dataitem(DataItemName1; "Gen. Journal Line")
        {
            column(Recipient_Bank_Account; "Recipient Bank Account")
            {
            }

            column(Amount; Amount)
            {
            }

            column(Account_No_; "Account No.")
            {
            }

            column(Document_No_; "Document No.")
            {
            }



            dataitem(DataItemName2; Vendor)
            {
                DataItemLink = "No." = DataItemName1."Account No.";
                SqlJoinType = InnerJoin;

                column(Our_Account_No_; "Our Account No.")
                {

                }

                column(Vendor_Name; Name)
                { }

                column(Creditor_No_; "Creditor No.")
                { }

            }


        }
    }
}

But as soon as I add a third DataItem it does not compile anymore.

add3DataItem.png

Any help would be greatly appreciated.

Thanks

  • Samantha73 Profile Picture
    3,378 on at

    In this case, you have to have the "Vendor Bank Account" table inside "vendor" data item

    general journal

           Vendor

                     Vendor bank account

  • landcrab2 Profile Picture
    35 on at

    Thanks for the response. New to AL and coding in general. Don't see how "Vendor Bank Account" is inside "Vendor" - curly brackets appear to be in the right place. What specifically do I need to change please?

    query 53000 TestQuery

    {

       QueryType = API;

       APIPublisher = 'Test';

       APIGroup = 'GroupName';

       APIVersion = 'v2.0';

       EntityName = 'TestQuery';

       EntitySetName = 'TestQuerys';

       elements

       {

           dataitem(DataItemName1; "Gen. Journal Line")

           {

               column(Recipient_Bank_Account; "Recipient Bank Account")

               {

               }

               column(Amount; Amount)

               {

               }

               column(Account_No_; "Account No.")

               {

               }

               column(Document_No_; "Document No.")

               {

               }

               dataitem(DataItemName2; Vendor)

               {

                   DataItemLink = "No." = DataItemName1."Account No.";

                   SqlJoinType = InnerJoin;

                   column(Our_Account_No_; "Our Account No."){}

                   column(Vendor_Name; Name)

                   {

                   }

                   column(Creditor_No_; "Creditor No.")

                   {

                   }

               }

               dataitem(DataItemName3;"Vendor Bank Account")

               {

                   DataItemLink = "Bank Account No." = DataItemName1."Account No.";

                   SqlJoinType = InnerJoin;

                   column(Bank_Account_No_;"Bank Account No."){}

                   column(Vendor_No_;"Vendor No."){}

               }

           }

       }

    }

  • Samantha73 Profile Picture
    3,378 on at

    Something like below:

    query 53010 TestQuery

    {

      QueryType = API;

      APIPublisher = 'Test';

      APIGroup = 'GroupName';

      APIVersion = 'v2.0';

      EntityName = 'TestQuery';

      EntitySetName = 'TestQuerys';

      elements

      {

          dataitem(DataItemName1; "Gen. Journal Line")

          {

              column(Recipient_Bank_Account; "Recipient Bank Account")

              {

              }

              column(Amount; Amount)

              {

              }

              column(Account_No_; "Account No.")

              {

              }

              column(Document_No_; "Document No.")

              {

              }

              dataitem(DataItemName2; Vendor)

              {

                  DataItemLink = "No." = DataItemName1."Account No.";

                  SqlJoinType = InnerJoin;

                  column(Our_Account_No_; "Our Account No."){}

                  column(Vendor_Name; Name)

                  {

                  }

                  column(Creditor_No_; "Creditor No.")

                  {

                  }

               dataitem(DataItemName3;"Vendor Bank Account")

              {

                  DataItemLink = "Bank Account No." = DataItemName1."Account No.";

                  SqlJoinType = InnerJoin;

                  column(Bank_Account_No_;"Bank Account No."){}

                  column(Vendor_No_;"Vendor No."){}

              }

              }

          }

      }

    }

  • Suggested answer
    JAngle Profile Picture
    159 on at

    Queries are certainly easier to construct but if you wanted a different object type with no indentation rules, like a query; perhaps this is worth a thought: joshanglesea.wordpress.com/.../

    This blog itself is for a different topic but the idea is similar. Have a function call within an api page so you can retrieve data from other tables

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 August Top 10 Community Leaders

These are the community rock stars!

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

#1
11manish Profile Picture

11manish 9 Super User 2026 Season 2

#2
André Arnaud de Calavon Profile Picture

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

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans