Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

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

API development - combine data from 2 tables

(2) ShareShare
ReportReport
Posted on by 2,963
Hi Everyone
Can a API combine data from two table for example sales posted invoice line and posted credit line so the total Qty by item is sum of invoice qty - Credit Qty?
  • Vahid Ghafarpour Profile Picture
    11,855 Super User 2025 Season 1 on at
    API development - combine data from 2 tables
    If any of the responses helped resolve your issue, please take a moment to mark the best answer. This helps others in the community quickly find solutions to similar problems.

    To do this, simply click the "Does this answer your question?" button on the most helpful response and like the helpful posts. If your issue is still unresolved, feel free to provide more details so the community can assist further!

    Thanks for being an active part of the Dynamics 365 Community! 😊
  • Suggested answer
    YUN ZHU Profile Picture
    85,670 Super User 2025 Season 1 on at
    API development - combine data from 2 tables
    Hi, hope the following helps.
    Dynamics 365 Business Central: API query type (Develop a custom API using Query)
     
    Thanks.
    ZHU
  • Suggested answer
    Ramesh Kumar Profile Picture
    5,458 on at
    API development - combine data from 2 tables
    Hi Samantha,
     
    I would say yes and developer should be able to do it as lot of user what to have Header and line details combined. In your case creating combined table with posted invoice lines and posted credit lines.
     
    query 50000 "Item Sales Quantities"
    {
        QueryType = API;
        APIPublisher = 'yourpublisher';
        APIGroup = 'yourgroup';
        APIVersion = 'v1.0';
        EntityName = 'itemSalesQuantity';
        EntitySetName = 'itemSalesQuantities';
        dataitem(SalesInvoiceLine; "Sales Invoice Line")
        {
            DataItemLink = "Item No." = field("Item No.");
            sum("Quantity");
        }
        dataitem(SalesCreditMemoLine; "Sales Credit Memo Line")
        {
            DataItemLink = "Item No." = field("Item No.");
            sum("Quantity");
        }
    }
     
     
     
    Thanks
    Ramesh
     
    If this was helpful, please check the "Does this answer your question?" box and mark it as verified.
     
     
  • Gerardo Rentería García Profile Picture
    20,775 Most Valuable Professional on at
  • Suggested answer
    Khushbu Rajvi. Profile Picture
    17,504 Super User 2025 Season 1 on at
    API development - combine data from 2 tables
    you can create an API query in Business Central that combines data from the Sales Invoice Line and Sales Cr. Memo Line tables to calculate the net quantity per item.
    Something like below.
    query 50100 "Sales Net Qty API"
    {
        APIPublisher = 'yourPublisher';
        APIGroup = 'yourGroup';
        APIVersion = 'v1.0';
        EntityName = 'SalesNetQty';
        EntitySetName = 'SalesNetQtys';
        elements
        {
            dataitem(SalesInvoiceLine; "Sales Invoice Line")
            {
                column(ItemNo; "No.") { }
                column(InvoiceQty; Sum("Quantity")) { }
                dataitem(SalesCreditMemoLine; "Sales Cr.Memo Line")
                {
                    DataItemLink = "No." = SalesInvoiceLine."No.";
                    column(CreditQty; Sum("Quantity")) { }
                }
                column(NetQty; InvoiceQty - CreditQty) { }
            }
        }
    }
     
    Adding more: https://community.dynamics.com/forums/thread/details/?threadid=db20aa0d-d086-4d45-bb24-3d15df4e60c5
  • Suggested answer
    Jainam M. Kothari Profile Picture
    9,695 on at

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

Ramesh Kumar – Community Spotlight

We are honored to recognize Ramesh Kumar as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

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

#1
Sohail Ahmed Profile Picture

Sohail Ahmed 2,655

#2
Mansi Soni Profile Picture

Mansi Soni 1,574

#3
YUN ZHU Profile Picture

YUN ZHU 1,453 Super User 2025 Season 1

Featured topics

Product updates

Dynamics 365 release plans