Skip to main content

DkHome - Create customer

Dynamics NAV - Create Customer This document describes the process of creating a new customer in Microsoft Dynamics NAV from App4Sales. Th...

Updated over a week ago

Dynamics NAV - Create Customer

This document describes the process of creating a new customer in Microsoft Dynamics NAV from App4Sales. The process is initiated when a user creates a new customer in the App4Sales application and the data is sent to the Dynamics NAV ERP system.

Trigger & Permissions

The customer creation process is triggered when a request is sent to the `OptA4SNewCustomers` endpoint. The connector info flags CreateCustomer and EditCustomer must be enabled for this functionality to work.

Payload Mapping

The incoming data is an XML payload that is mapped to a Dynamics NAV customer object. The following tables describe the field mappings.

Customer

App4Sales Field

Source Field (API/Excel/DB)

Logic/Notes

CustomerNo

CustomerCode

The customer code from App4Sales.

CustomerName

CustomerName

The name of the customer.

CustomerAddress

VisitAddress1

The first line of the visiting address.

CustomerAddress2

VisitAddress2

The second line of the visiting address.

CustomerPostCode

VisitPostCode

The postal code of the visiting address.

CustomerCity

VisitCity

The city of the visiting address.

CustomerCountryRegionCode

CountryCode

The country code.

CustomerSalesPersonCode

-

The salesperson code. It is determined by the following logic:
1. From the `UnknownElements` collection with the key `CustomerSalesPersonCode`.
2. From the `ResIdString` of the current sales representative.
3. From the `CustomerDefaultSalesPersonCode` connector setting.

CustomerGenBusPostingGroup

-

The general business posting group. It is determined by the following logic:
1. From the `UnknownElements` collection with the key `CustomerGenBusPostingGroup`.
2. From the `CustomerDefaultGenBusPostingGroup` connector setting.

CustomerVatBusPostingGroup

IsVatLiable, CountryCode

The VAT business posting group. The value is determined based on the VAT liability and country code. See the "Validation & Defaults" section for more details.

CustomerPostingGroup

-

The customer posting group. It is determined by the following logic:
1. From the `UnknownElements` collection with the key `CustomerPostingGroup`.
2. From the `CustomerDefaultPostingGroup` connector setting.

CustomerPhoneNo

Phone

The customer's phone number.

CustomerEMail

Email

The customer's email address.

CustomerInvoiceDiscCode

-

The customer invoice discount code. The value is taken from the `CustomerInvoiceDiscountCode` connector setting.

CustomerPriceGroup

UsesPrice

The customer price group. The code is retrieved from the `PriceLists` context based on the `UsesPrice` field.

CustomerPaymentTermsCode

PaymentCondition

The customer's payment terms code.

CustomerShipmentMethodCode

-

The shipment method code. It is determined by the following logic:
1. From the `UnknownElements` collection with the key `CustomerShipmentMethodCode`.
2. From the `CustomerShippingCodeMethod` connector setting.

CustomerShippingAgentCode

-

The shipping agent code. It is determined by the following logic:
1. From the `UnknownElements` collection with the key `CustomerShippingAgentCode`.
2. From the `CustomerShippingAgentCodeMethod` connector setting.

CustomerBaseCalenderCode

-

The base calendar code. The value is taken from the `CustomerBaseCalendarCode` connector setting.

CustomerLocationCode

-

The location code. The value is taken from the `CustomerLocationCode` connector setting.

CustomerCurrencyCode

UsesPrice

The currency code. It is retrieved from the price list and will be an empty string if it is the same as the `DefaultCustomerCurrencyCode` connector setting.

CustomerLanguageCode

LanguageCode

The language code. If not provided, the `CustomerDefaultLanguageCode` connector setting is used.

CustomerVatRegistrationNo

VatCode

The VAT registration number.

CustomerCreditLimitLCY

-

The customer's credit limit in local currency. The value is taken from the `UnknownElements` collection with the key `CustomerCreditLimitLCY`.

CustomerReminderTermsCode

-

The customer's reminder terms code. The value is taken from the `UnknownElements` collection with the key `CustomerReminderTermsCode`.

CustomerCustomerDiscGroup

-

The customer's discount group. The value is taken from the `UnknownElements` collection with the key `CustomerCustomerDiscGroup`.

Contact Person

App4Sales Field

Source Field (API/Excel/DB)

Logic/Notes

ContactName

ContactFullName

The full name of the contact person.

ContactAddress

VisitAddress1

The first line of the visiting address.

ContactAddress2

VisitAddress2

The second line of the visiting address.

ContactPostCode

VisitPostCode

The postal code of the visiting address.

ContactCity

VisitCity

The city of the visiting address.

ContactCountryRegionCode

CountryCode

The country code.

ContactPhoneNo

Phone

The contact person's phone number.

ContactMobilePhoneNo

Mobile

The contact person's mobile number.

ContactLanguageCode

LanguageCode

The language code. If not provided, the `CustomerDefaultLanguageCode` connector setting is used.

ContactEmail

Email

The contact person's email address.

ContactType

-

Hardcoded to "Person".

ContactSalutationCode

-

The salutation code. It is determined by the following logic:
1. From the `UnknownElements` collection with the key `ContactSalutationCode`.
2. From the `CustomerDefaultSalutationCode` connector setting.

Delivery Address

App4Sales Field

Source Field (API/Excel/DB)

Logic/Notes

CustomerShipToAddressCode

-

The ship-to address code. The value is taken from the `CustomerShipToAddressCode` connector setting, or "A4S" if the setting is not specified.

CustomerShipToAddressName

CustomerName

The name of the customer.

CustomerShipToAddressAddress

DeliveryAddress1

The first line of the delivery address.

CustomerShipToAddressAddress2

DeliveryAddress2

The second line of the delivery address.

CustomerShipToAddressPostCode

DeliveryPostCode

The postal code of the delivery address.

CustomerShipToAddressCity

DeliveryCity

The city of the delivery address.

CustomerShipToAddressPhoneNo

Phone

The customer's phone number.

CustomerShipToAddressContact

ContactFullName

The full name of the contact person.

CustomerShipToAddressLocationCode

-

The location code. The value is taken from the `CustomerLocationCode` connector setting.

CustomerShipToAddressShipmentMethodCode

-

The shipment method code. The value is taken from the `CustomerShippingCodeMethod` connector setting.

CustomerShipToAddressShippingCode

-

The shipping agent code. The value is taken from the `CustomerShippingAgentCodeMethod` connector setting.

CustomerShipToAddressServicecodeCode

-

The service code. The value is taken from the `CustomerShippingAgentServiceCodeMethod` connector setting.

CustomerShipToAddressEmail

Email

The customer's email address.

Validation & Defaults

  • If the incoming customer information cannot be read, the process is aborted.

  • All null string values in the customer, contact, and address objects are converted to empty strings before sending them to NAV.

  • The VAT business posting group (`CustomerVatBusPostingGroup`) is determined by the following logic:

    • If the customer's country is the domestic country (defined in the `VatDomesticCountryCode` setting), the `VatDomesticPostingGroup` setting is used.

    • If the customer's country is in the European Union, the `VatEuLiablePostingGroup` or `VatEuNotLiablePostingGroup` setting is used, depending on the `IsVatLiable` flag.

    • Otherwise, the `VatOtherPostingGroup` setting is used.

  • If a delivery address is not provided, the visiting address is used as the delivery address.

Response & Error Handling

The connector calls the `CreateCustomer` method of the Dynamics NAV web service. If the call is successful, the ERP returns the new customer number, which is then returned by the connector. If the call fails, an error message is logged and returned by the connector. The connector can handle `FaultException` (SOAP faults) and general exceptions.

Related Settings & Prerequisites

  • CustomerDefaultSalesPersonCode: Default salesperson code for new customers.

  • CustomerDefaultGenBusPostingGroup: Default general business posting group for new customers.

  • CustomerDefaultPostingGroup: Default customer posting group for new customers.

  • CustomerShippingCodeMethod: Default shipping method for new customers.

  • CustomerShippingAgentCodeMethod: Default shipping agent for new customers.

  • CustomerBaseCalendarCode: Default base calendar code for new customers.

  • CustomerLocationCode: Default location code for new customers.

  • DefaultCustomerCurrencyCode: The default currency for new customers.

  • CustomerDefaultLanguageCode: Default language code for new customers.

  • CustomerInvoiceDiscountCode: Default invoice discount code for new customers.

  • CustomerDefaultSalutationCode: Default salutation code for new contacts.

  • CustomerShipToAddressCode: The code for the ship-to address. Defaults to "A4S".

  • CustomerShippingAgentServiceCodeMethod: Default shipping agent service code for new customers.

  • VatDomesticCountryCode: The country code of the domestic country for VAT calculation.

  • VatDomesticPostingGroup: The VAT posting group for domestic customers.

  • VatEuLiablePostingGroup: The VAT posting group for EU customers that are VAT liable.

  • VatEuNotLiablePostingGroup: The VAT posting group for EU customers that are not VAT liable.

  • VatOtherPostingGroup: The VAT posting group for customers outside the EU.

Did this answer your question?