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

Announcements

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

I have the same question (0)
  • Samantha73 Profile Picture
    3,297 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,297 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
    150 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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

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

#1
OussamaSabbouh Profile Picture

Liquid error: Object of type 'Adxstudio.Xrm.Web.Mvc.Liquid.EntityReferenceDrop' cannot be converted to type 'System.String'. Liquid error: Object of type 'System.Boolean' cannot be converted to type 'System.String'. Liquid error: Object of type 'System.Boolean' cannot be converted to type 'System.String'. Liquid error: Object of type 'System.Boolean' cannot be converted to type 'System.String'. OussamaSabbouh 2,068 Super User 2026 Season 1

#2
Dhiren Nagar Profile Picture

Liquid error: Object of type 'Adxstudio.Xrm.Web.Mvc.Liquid.EntityReferenceDrop' cannot be converted to type 'System.String'. Liquid error: Object of type 'System.Boolean' cannot be converted to type 'System.String'. Liquid error: Object of type 'System.Boolean' cannot be converted to type 'System.String'. Liquid error: Object of type 'System.Boolean' cannot be converted to type 'System.String'. Dhiren Nagar 1,194 Super User 2026 Season 1

#3
YUN ZHU Profile Picture

Liquid error: Object of type 'Adxstudio.Xrm.Web.Mvc.Liquid.EntityReferenceDrop' cannot be converted to type 'System.String'. Liquid error: Object of type 'System.Boolean' cannot be converted to type 'System.String'. Liquid error: Object of type 'System.Boolean' cannot be converted to type 'System.String'. Liquid error: Object of type 'System.Boolean' cannot be converted to type 'System.String'. YUN ZHU 1,123 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans