Skip to main content

DynamicsNav - Send order

DynamicsNav Connector - SendOrderToBackoffice This document details the process by which App4Sales orders are sent to the Dynamics NAV ba...

Updated over a week ago

DynamicsNav Connector - SendOrderToBackoffice

This document details the process by which App4Sales orders are sent to the Dynamics NAV back office system via the SendOrderToBackoffice function. This function translates App4Sales order data into a Dynamics NAV XMLPort structure (RootCreateOrder) and transmits it to the ERP. It handles order headers, order lines, and shipping addresses, including various transformations and validations based on connector settings. The process also captures the order number returned by Dynamics NAV and updates the internal App4Sales order record.

Order Header Logic

Customer selection, numbering, order-type routing, payment/shipping fields.

App4Sales Field

Source Field (API/Excel/DB)

Logic/Notes

Customer Code

order.Customer.CustomerCode

Maps the App4Sales customer code to the Dynamics NAV customer number.

Your Reference

order.Reference or order.YourReference

If Use reference as your reference setting is enabled, order.Reference is used; otherwise, order.YourReference. Limited to 35 characters.

Requested Delivery Date

order.OrderDate

The App4Sales order date, formatted as a date string.

Campaign Number

order.OrderType.ValueToBackoffice or order.Reference

Derived from the second part of the order type (e.g., "Order:FPS" uses "FPS") or directly from the order reference if no order type campaign is specified.

Notes

order.Notes, order.YourReference, order.Reference

Combines order.Notes with either order.YourReference or order.Reference based on the Use reference as your reference setting. Separated by ". ".

Document Type

order.OrderType.ValueToBackoffice

The first part of the order type (e.g., "Order:FPS" uses "Order"). Default is "Order" if not specified.

Ship To Code

order.AlternateAddress, order.Customer.Addresses

If an alternate address is provided and matches an existing delivery address for the customer, the AddressLine3 of that address is used as the ship-to code.

Sales Person

order.Salesrep

The sales representative code is set if the Set sales rep on order setting is enabled.

Customer Ship To Address

order.AlternateAddress, order.CustomerGuid, connector settings

A new ship-to address is created in Dynamics NAV if an alternate address is provided and it is not an existing delivery address for the customer.

Line & Pricing Logic

Source fields for items, quantities, prices, discounts, VAT adjustments.

App4Sales Field

Source Field (API/Excel/DB)

Logic/Notes

Line Number

(index of order line)

Sequential number for each order line, starting from 0.

Item Number

orderline.ItemCode

The item code from the App4Sales order line.

Quantity

orderline.Quantity

The quantity of the item, formatted as a number.

Unit Price

orderline.Price, orderline.Discount, order.Source, connector settings

If the Send order line prices to Nav setting is enabled, or if the order source matches sources configured in Send order line prices to Nav based on source, the unit price is sent. If Send order line discount to Nav is enabled and a discount is applied, the unit price is recalculated: orderline.Price / (100 - orderline.Discount) * 100. Formatted as a number with 5 decimal places.

Line Discount Percentage

orderline.Discount, connector settings

The discount percentage from the order line, formatted as a number with 5 decimal places, only if Send order line discount to Nav is enabled.

Instruction

orderline.Instruction, connector settings

The instruction text for the order line, only if Enable order line instruction setting is enabled.

Charges & Attachments

Freight/payment surcharges, PDF/JSON exports, signature/image uploads.

This connector does not explicitly handle charges, attachments, or extra payloads. Functionality related to these aspects is not implemented in the SendOrderToBackoffice process or associated DTOs.

Responses & Error Handling

Returned order numbers, duplicate detection, retry/backoff strategies.

The connector attempts to create the order in Dynamics NAV via the _client.CreateOrder method. If successful, it extracts the order number from the returned RootCreateOrder.SalesHeader[0].SalesHeaderOrderNo. This order number is then used to update the internal App4Sales order record. If the order number is empty or null, an error is returned. Errors during the API call (e.g., network issues, Dynamics NAV specific errors) are caught, logged, and returned to App4Sales with an ERROR prefix and the exception message.

Domain Specifics / Extension Section

Order Header Logic

The order.ApplyWebshopDiscountOnOrderLines method is called before converting the order to a Dynamics NAV entity, indicating that webshop discounts are processed at the App4Sales level and applied to order lines prior to transmission.

Customer Ship To Address Logic

When an alternate address is provided for an order, the connector first checks if it corresponds to an already existing delivery address for the customer in App4Sales. If it's not an existing address, a new ship-to address is constructed and sent to Dynamics NAV.

App4Sales Field

Source Field (API/Excel/DB)

Logic/Notes

Ship To Address Name

alternate.EstablishmentName

The establishment name from the alternate address.

Ship To Address Name 2

(Empty String)

This field is always sent as an empty string.

Ship To Address Address

alternate.AddressLine1

The first address line from the alternate address.

Ship To Address Address 2

alternate.AddressLine2

The second address line from the alternate address.

Ship To Address Code

(Empty String)

This field is always sent as an empty string.

Ship To Address Post Code

alternate.PostCode

The postal code from the alternate address.

Ship To Address City

alternate.City

The city from the alternate address.

Ship To Address Country Region

alternate.Iso2 or alternate.Country

If the Send ISO Code As Ship To Address Country Region Order Field setting is enabled, the ISO2 country code is used; otherwise, the full country name is used.

Ship To Address Email

alternate.Email or order.Description1

The email from the alternate address if valid; otherwise, order.Description1 if it's a valid email address.

Ship To Address Phone No

alternate.Phone or order.Description2

The phone number from the alternate address if not empty; otherwise, order.Description2.

Related Settings & Prerequisites

  • Use reference as your reference: (Boolean) If enabled, the order's Reference field is used for Dynamics NAV's "Your Reference" field in the sales header, and the original "Your Reference" is appended to the notes. Otherwise, YourReference is used for "Your Reference" and Reference is appended to the notes.

  • Set sales rep on order: (Boolean) If enabled, the sales representative associated with the App4Sales order is sent to Dynamics NAV.

  • Send order line discount to Nav: (Boolean) If enabled, discount percentages on order lines are sent to Dynamics NAV, and the unit price is recalculated based on the discount.

  • Send order line prices to Nav: (Boolean) If enabled, unit prices for order lines are sent to Dynamics NAV.

  • Send order line prices to Nav based on source: (Text) A comma-separated list of order sources. If the order's source matches one in this list, unit prices are sent to Dynamics NAV regardless of the Send order line prices to Nav setting.

  • Enable order line instruction: (Boolean) If enabled, any instruction text on the App4Sales order line is sent to Dynamics NAV.

  • Send ISO Code As Ship To Address Country Region Order Field: (Boolean) If enabled, the ISO2 country code is used for the ship-to address country region; otherwise, the full country name is used.

Did this answer your question?