web
You’re offline. This is a read only version of the page.
close
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

(Business Central) purchase/sales invoice line item Ids when inserting

(0) ShareShare
ReportReport
Posted on by

When inserting a new purhcase/sales invoice & line items, I noticed that the line items "itemId" property only recognises the id's from the "Item" table ant any other table such as "resources" or "Fixed Asset" etc, hence the message 

The field Item Id of table Purch. Inv. Line Aggregate contains a value ({itemId}) that cannot be found in the related table (Item)
 
The current HTTTPOST endpoint I am pointing to is :
api/v1.0/companies(companyId)/purchaseInvoices?$expand=purchaseInvoiceLines
With an example body:
{
            "vendorId": "vendorId",
            "invoiceDate": "2018-02-02",
            "dueDate": "2022-01-01",
            "currencyCode": "JPY",
            "purchaseInvoiceLines": [
                {
                    "lineType": "Resource",
                    "itemId" : "Item Id that is a resource instead of type item",
                    "quantity": 2,
                    "discountAppliedBeforeTax": true,
                    "expectedReceiptDate": "2019-01-01"
                }
            ]
}
- I would firstly like to know if there is any other information I am missing from this body that I would need to let the invoice line item know where to look, do I need to give the item id of the resource to a different property other than itemId?
- I would also like to know where (in the business central NAV extension world) does this endpoint live in? What table/page/codeunit should I be investigating?
- Thirdly, is there any other recommended endpoint I should be using in order to push to purchase/sales invoice & it's lineItems?
I have the same question (0)
  • Suggested answer
    Spencer A-C Profile Picture
    50 on at

    Hi,

    For creating invoices and invoice lines, I'd use the ODATA web services that business central provide within the Web Services table. Page 6404 and 6405 for purchases and 6402 and 6403 for sales. 

    Then when you're creating the line, you need to include the document type, document number and line number. This will then tell the API to attach the line to specified document with the line number equal to the line number you provide. The below call is what I use for creating a purchase invoice line.

    pastedimage1603979425274v1.png

    Kind regards

  • Community Member Profile Picture
    on at

    Thanks for your reply, how does the lineItem know what item we want to input there, as I can't see any indication of what item we're referring to in that body? also, in the endpoint I noticed that the company is searched via the companyName and not the id, is there any other way (such as using the id instead) that achieve the same desired endpoint result?

  • Suggested answer
    Spencer A-C Profile Picture
    50 on at

    So for items, where type = G/L Account, change that to Item and then supply the Item Code in "number".

    So BC has a variety of different APIs that you can manipulate. The one you're using in the original post is a v1.0 API, which uses ID's within the URL call. A lot of the time the IDs are unknown when you're calling the APIs which is why the standard APIs they give are the ODATA APIs which you just specify the environment and company name (the one that is in my example). The environment in most people's cases is Production and the Company Name is normally known prior to the call.

    The following link goes into more detail about the different endpoints docs.microsoft.com/.../endpoints-apis-for-dynamics

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,238

#2
YUN ZHU Profile Picture

YUN ZHU 773 Super User 2025 Season 2

#3
Sumit Singh Profile Picture

Sumit Singh 630

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans