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 :
Small and medium business | Business Central, N...
Suggested answer

API development - combine data from 2 tables

(2) ShareShare
ReportReport
Posted on by 3,199
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
    13,141 Super User 2025 Season 2 on at
  • Suggested answer
    Khushbu Rajvi. Profile Picture
    19,973 Super User 2025 Season 2 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
  • Gerardo Rentería García Profile Picture
    23,855 Most Valuable Professional on at
    API development - combine data from 2 tables
  • Suggested answer
    Ramesh Kumar Profile Picture
    7,523 Super User 2025 Season 2 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.
     
     
  • Suggested answer
    YUN ZHU Profile Picture
    93,870 Super User 2025 Season 2 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
  • Vahid Ghafarpour Profile Picture
    11,993 Super User 2025 Season 2 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! 😊

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…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

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

#1
Sumit Singh Profile Picture

Sumit Singh 2,179

#2
OussamaSabbouh Profile Picture

OussamaSabbouh 1,999

#3
YUN ZHU Profile Picture

YUN ZHU 1,892 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans