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

API development - combine data from 2 tables

(2) ShareShare
ReportReport
Posted on by 3,297
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?
I have the same question (0)
  • Suggested answer
    Jainam M. Kothari Profile Picture
    15,666 Super User 2026 Season 1 on at
  • Suggested answer
    Khushbu Rajvi. Profile Picture
    21,573 Super User 2026 Season 1 on at
    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
  • Gerardo Rentería García Profile Picture
    25,545 Most Valuable Professional on at
  • Suggested answer
    Ramesh Kumar Profile Picture
    7,545 Super User 2026 Season 1 on at
    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.
     
     
  • Suggested answer
    YUN ZHU Profile Picture
    97,931 Super User 2026 Season 1 on at
    Hi, hope the following helps.
    Dynamics 365 Business Central: API query type (Develop a custom API using Query)
     
    Thanks.
    ZHU
  • Vahid Ghafarpour Profile Picture
    12,216 Super User 2026 Season 1 on at
    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! 😊

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

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 'System.Boolean' cannot be converted to type 'System.String'. OussamaSabbouh 2,155 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

Liquid error: Object of type 'System.Boolean' cannot be converted to type 'System.String'. YUN ZHU 1,043 Super User 2026 Season 1

#3
Dhiren Nagar Profile Picture

Liquid error: Object of type 'System.Boolean' cannot be converted to type 'System.String'. Dhiren Nagar 955 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans