Back

Tech Tuesday: Creating a Sales Invoice using the Business Central OData API with SmartConnect.com

Published: Nov 06, 2026
Post Author Written by Pat Roth

In a previous Tech Tuesday article, we created a Business Central Sales Invoice with the long-established method of using the Business Central OData Page 43.

While this worked well, with the impending deprecation of the out-of-the-box Microsoft OData pages, our map will soon no longer be functional.

With that in mind, in this Tech Tuesday we will recreate the map using the Sales Invoice OData API destination in SmartConnect.com.

If you’d like to watch a video explaining this, see below or click here.

Business Central OData API vs. OData Page

While the Business Central OData API destination allows SmartConnect to create and update the Sales Invoices and lines, there are a number of differences in the mapping compared to the OData Page.

When using the OData Page for Business Central, we literally use the data entry page the same way a user would in the Business Central user interface.

There are a few advantages of using the OData Page itself, such as:

  • The fields that we see in the SmartConnect mapping window are the same field names we see on the Business Central UI.
  • The static values in drop-down list fields are typically the same values we would use when integrating to that field.
  • Almost every field in the UI is available to map in SmartConnect, since it is on the page.

There doesn’t seem to be a way to change the order in which the JSON data is processed by the OData page. This can lead to some odd situations where a field can’t seem to be set by SmartConnect and must be updated with a second call to the same page.

A disadvantage of using an OData Page is lower performance compared to the OData API. The advantage of using the OData API is that it performs better than an OData Page, and this destination will still work in the near future, whereas the OData Page won’t for out-of-the-box pages.

Disadvantages of using the OData API:

  • The field names are typically not the same field names that the UI would use, making it more difficult to discern which fields to map to.
  • There tend to be a lot fewer fields available on any API compared to the OData Page itself.

The two processes are similar in that we could use Microsoft Dynamics Integration Manager or a GP Macro to create a record by automating the GP UI. I could also use SmartConnect/eConnect to create the same data via an eConnect stored procedure.

While using the macro is much quicker and more accurate than a person entering the same data, the eConnect stored procedure will be much quicker than either other approach.

Creating a Business Central Sales Invoice using OData API

The first thing to verify is that you have the v2.0 API Route enabled in your Dynamics 365 Business Central OData Connector.

Mark at least the v2.0 route, as shown, since it contains the destination we’re using in this article.

We’ll use the same document format as previously used, but with a different Document Number field. The data is otherwise the same.

After creating the new Text File data source, start the new map and preview the data.

Group your data by DocNo so that all three lines will go into the same invoice. Initially, we will use our DocNo value as our BC Sales Invoice Number instead of letting it default.

576 Pic16

Our Target will be Dynamics 365 Business Central OData Api.

After choosing your Business Central instance, pick the v2.0 route that we selected earlier.

Then, you need to tell SmartConnect which endpoint/destination you need. Press the Add Service button and choose salesInvoices from the lookup.

That just gives the document “header”; you’ll need the lines as well.

On the salesInvoices node, press the + button to add a “child” node. Pick salesInvoiceLines, and your screen should look like the screenshot.

Please note that unlike the OData Page destination, we have a “Rollback document on failure” feature. This makes sure that if there is an error on the document, SmartConnect/Business Central will “roll back” the document to the initial state if updating an existing one, or remove it if this was a new document.

Next, move to the Integration tab. The salesInvoices node is selected by default.

Because you only want one header record, you need to “group” the three lines into one. Select the Group Data checkbox and then set Group On to DocNo and CustomerID. DocNo matches the Key Fields selected for the map. Because you want to be able to handle updates to the existing record, the Update Existing checkbox is also marked.

Just as with the OData Page, SmartConnect uses the “Group On” fields to verify if a record exists or not, so you must pick Group On field(s) that make the record unique in Business Central.

Opening the salesInvoices node on the Target Integration tab, we notice there aren’t nearly as many fields to map, which isn’t an issue here since we only need the essential data for this integration.

Next, you’ll want to map your DocNo field, but we don’t see the typical “No” field that almost all of the OData pages use for the key field. In this case, it would be the Sales Invoice Number, which would be mapped to DocNo.

For OData API routes, this is almost always the number field, spelled out in full this time.

There is only one “customer” field, so map your CustomerID column to customerNumber.

Finally, you can either let the invoiceDate default or provide one with a quick JavaScript calculation for today’s date.

Change the Target Lines to be salesInvoicesLines and look at the mapping.

A few of the fields are obvious, so the unitPrice, quantity, lineType, and sequence are filled in.

One concerning thing here about the documentId is that the “document” field is the only one available to map. I’m sure this won’t work because we see the data type is Edm.Guid and not Edm.String.

The lineType is also a bit of a concern as the data type isn’t a simple Edm.Int32.

The lineObjectNumber is also a bit of a guess, but none of the other fields look like they would be right so we’ll try it.

Testing

Before we test, we need to set the grouping on the Source Grouping tab.

We need to tell SmartConnect how to look up the “existing sales invoice lines” the same way as the header record. Mark LineNo (since it’s mapped) and DocNo.

Not surprisingly, the DocNo field failed, as we expected. Business Central wants the GUID “Id” of the sales invoice, and not the actual text value.

As SmartConnect is going to call the API and create the sales invoice “header” record first, we should be able to create an OData API lookup to get that value.

But while this should work, it isn’t the most efficient way to get that value.

The OData API endpoint currently has a unique ability that none of the other endpoints share, which can help us with this.

When SmartConnect makes the API call to Business Central, Business Central returns the entire new record data that was created.

Ordinarily, SmartConnect just throws that away and we don’t have access to that information, such as the ID that we require. But if we select the salesInvoices node and press the three dots button, it opens the Edit Services – salesInvoices window.

576 Pic24

Here we can use the “Add parent field” button to select the ID field that is being returned by the call, so it can be used as another data field or in a lookup.

After selecting the ID field and going back to the salesInvoicesLines mapping, we can now see a new source field SALESINVOICES_ID that is of type “Parent Source Column“. This new field will contain our ID GUID value that we can map to the documentId field, which will now properly attach the salesInvoiceLine to the header record it belongs to.

After mapping the field, we do have to unmark the DocNo field as a “Group On” field. SmartConnect will give an error otherwise.

Unmarking this field won’t affect the Business Central OData API lookup that SmartConnect will do to verify if the record exists or not. It knows how to find the sales line due to the relationship of the entities and the marked LineNo grouped field.

Re-running the integration resolves that problem, but another issue surfaces.

This one was unexpected since we assumed that the OData API would be using the same values that the BC OData Page did. It doesn’t: this time “Comment” is valid and “G/L Account” is not, but Business Central helpfully gives us the correct values.

We could create a translation table to handle this, but since it appears that we just have one incorrect value, we can just use a simple calculation to get the correct values back for our existing data.

if (this._LINETYPE === "G/L Account") {
   return "Account";
} else {
   return this._LINETYPE;
}

After creating the CALC_LINE_TYPE calculation in the Additional Columns window and mapping it to the lineType destination field, the integration ran successfully, and the Sales Invoice was properly created using the provided Sales Invoice Number PTR0003.

Now that we have the integration working successfully, we will clone the map and switch it to let Business Central default the document number instead of it being provided.

Cloning the Integration

After cloning the integration (or modifying the existing one), we’ll edit the new integration.

This is as easy as unmapping the DocNo field, but if we want to update existing records, we need a unique value to use for the Group On fields. We could instead use our DocNo field as the externalDocumentNumber. Together with the CustomerID field, that uniquely identifies the record to update.

Looking at the salesInvoices node, we just remove the mapping to “number” and instead map it to the externalDocumentNumber field as seen in the screenshot.

The Update Existing checkbox stays marked and we don’t need to change the Group On fields since DocNo has been repurposed and CustomerID was already marked.

You don’t have to change anything for the salesInvoicesLines node.

Since there wasn’t a “Document Number” to map to our data, there isn’t anything to fix on this node.

Running the integration was successful. Looking in the Business Central Sales Invoices list, we can see the previous invoice PTR0003 that was created initially, and the new invoice just created with the “next number”. The External Document Number is set to PTR0003 as expected.

Congratulations, we’ve successfully built an integration to create a Microsoft Dynamics 365 Business Central Sales Invoice with multiple line types that handles “inserts” as well as “updates” using the Business Central OData Api endpoint.

Both integrations and the source data can be downloaded using the link below.

Feeling stuck? Get the support and guidance you need to help you power through any data challenge

We're on your integration team. Connect with our people and let us know how we can help you.