Business Central - POST sales invoice line using REST API - setting multiple dimension values

1.6k views Asked by At

We use Business Central cloud API to POST sales invoices from other system

After creating the the sales invoice we create sales invoice lines to it by using {BC Endpoint}/SalesInvoiceLine API call but we are able to enter only two shortcut dimensions eg.

"Shortcut_Dimension_1_Code": "{value_fordim1}", "Shortcut_Dimension_2_Code": "{value_fordim2}

HOWEVER we need to set 4 dimensions for sales invoice line

We have tried to search MS API documentation for this situation but no luck

So far we haven't found a way to set all 4 dimension values to sales invoice line directly.

Current assumption is that we should somehow add new dimension set entry to BC (or search suitable combination from Dimension Set Entry table) and then somehow tie the sales invoice line to that Dimension Set Entry ID. However we do not know what API calls we could use for this.

Any guidance or help appriciated

2

There are 2 answers

1
Total_noob_on_GIS On BEST ANSWER

We were able to solve this by using:

POST {BC-endpoint}/SalesInvoiceLine call

and just by entering the additional shortcut dimensions to the body

{

.......

"ShortcutDimCode4": "{value_for_dim4}",
"ShortcutDimCode5": "{value_for_dim5}"

}

1
Alexander Drogin On

In API v2.0 both entities salesInvoice and salesInvoiceLine contain a child object dimensionSetLines. If you run a request on the $metadata endpoint, you can find the definition in the API metadata.

<EntityType Name="dimensionSetLine">
<Key>
<PropertyRef Name="id"/>
</Key>
<Property Name="id" Type="Edm.Guid" Nullable="false"/>
<Property Name="code" Type="Edm.String" Nullable="false" MaxLength="20"/>
<Property Name="parentId" Type="Edm.Guid"/>
<Property Name="parentType" Type="Microsoft.NAV.dimensionSetEntryBufferParentType"/>
<Property Name="displayName" Type="Edm.String" MaxLength="30"/>
<Property Name="valueId" Type="Edm.Guid"/>
<Property Name="valueCode" Type="Edm.String"/>
<Property Name="valueDisplayName" Type="Edm.String" MaxLength="50"/>

To view all dimensions on an invoice, send a GET request on

https://<Tenant URL>/api/v2.0/salesInvoices(<Invoice ID (GUID)>)?$expand=dimensionSetLines

To create an invoice with multiple dimension, include the dimensionSetLines object in the salesInvoice entity when sending the POST request.

{
    "invoiceDate": "2024-01-22",
    "postingDate": "2024-01-22",
    "customerNumber": "10000",
    "dimensionSetLines": [
        {
            "code": "SALESCAMPAIGN",
            "valueCode": "SUMMER"
        },
        {
            "code": "PROJECT",
            "valueCode": "VW"
        },
        {
            "code": "BUSINESSGROUP",
            "valueCode": "INTERCOMPANY"
        }
    ]
}