Skip to main content

NetSuite - Send order

NetSuite Connector - Send Order To Backoffice This function synchronizes App4Sales orders to the NetSuite ERP. It processes order headers...

Updated over a week ago

NetSuite Connector - Send Order To Backoffice

This function synchronizes App4Sales orders to the NetSuite ERP. It processes order headers, order lines, and various associated details, converting them into a NetSuite Sales Order. The process involves retrieving customer and sales representative subsidiaries, setting the default price level, and then delegating the order creation and transmission to a specific order handler based on the order type. Upon successful creation in NetSuite, the assigned NetSuite transaction ID is returned and stored in App4Sales.

Data Source Configuration

The connector primarily uses the App4Sales internal order object (Models.ObjectsDb.Order) as its data source. It interacts with the NetSuite API for creating the sales order and retrieving the assigned transaction ID. Subsidiary information for customers and sales representatives is fetched internally from the connector's customer repository. Price levels are determined by the connector settings and retrieved from the pricelists repository.

Data Mapping Table (Order Header)

App4Sales Field

Source Field (API/Excel/DB)

Logic/Notes

Order Date

srcOrder.OrderDate

Mapped to NetSuite's shipDate. If Leave ship date empty setting is enabled, this field will not be sent.

Customer

srcOrder.Customer

Mapped to NetSuite's entity. Converted to a RecordRef using CreateCustomerRecordRef based on the customer's internal ID.

Order Status

N/A

Hardcoded to _pendingApproval in NetSuite for newly created sales orders.

Memo (Notes)

srcOrder.Notes

Mapped directly to NetSuite's memo field.

Subsidiary

order.Salesrep, Use the subsidiary of the sales rep, Default customer subsidiary

Determined by CustomersRepository.GetSubsidiary based on the sales representative or a default customer subsidiary setting. Mapped to NetSuite's subsidiary.

Sales Representative

srcOrder.Salesrep

Mapped to NetSuite's salesRep field. The external ID of the sales representative is retrieved using the TryGetSalesRepExternalId method.

Customer PO Number

srcOrder.YourReference

Mapped to NetSuite's otherRefNum. This mapping is applied if the Set Your Reference to PO number setting is enabled. If this setting is enabled and YourReference is empty, an error will occur.

Payment Terms

srcOrder.Customer?.PaymentConditionCode or Default payment condition ID for orders setting

Mapped to NetSuite's terms field using the internal ID of the payment condition. The customer's payment condition code is used first, falling back to the default payment condition ID from settings.

Shipping Address

srcOrder.AlternateAddress or srcOrder.Customer?.Addresses (type: Delivery)

Mapped to NetSuite's shipAddressList (if ExternalId is present) or shippingAddress (if no ExternalId). Prioritizes AlternateAddress, then the main delivery address from the customer.

Billing Address

srcOrder.Customer?.Addresses (type: Visit)

Mapped to NetSuite's billAddressList (if AddressId is present) or billingAddress (if no AddressId). This mapping is applied if the Use visit address as invoice for orders setting is enabled. Prioritizes the main visit address from the customer.

Class

Custom Data (Order Type value)

Mapped to NetSuite's class field. This is applied if the Set Class for Sales Order Based on Passed Order Type setting is enabled and a corresponding value exists in the custom data for the order type.

Location

Default location ID setting

Mapped to NetSuite's location field if the Default location ID setting is provided.

Data Mapping Table (Order Lines)

App4Sales Field

Source Field (API/Excel/DB)

Logic/Notes

Item

line.item

Mapped to NetSuite's item field. Converted to a RecordRef using CreateItemRecordRef based on the item's internal ID.

Quantity

line.Quantity

Mapped to NetSuite's quantity field. Converted from decimal to double.

Amount (Line Price)

line.Price

Mapped to NetSuite's amount field if custom pricing is allowed. Calculated as line.Price * line.quantity. Custom pricing is allowed if Can use custom prices setting is enabled or if the source is a backoffice.

Line Location

Default location ID setting

Mapped to NetSuite's location field if the Default location ID setting is provided. This applies to individual order lines.

Custom Field Mappings (Order Header)

App4Sales Field

Source Field (API/Excel/DB)

Logic/Notes

Contact Person

srcOrder.ContactPerson?.ContactId

Mapped to a custom field specified by the Contact custom field name setting. The App4Sales Contact ID is used as the internal ID for the NetSuite custom field.

Boolean Custom Fields

N/A

Custom boolean fields specified in the Order bool custom field name setting are set to true.

Trade Type

Custom Data (from order type)

Mapped to a custom field specified by the Trade type custom field name setting. If the custom data value is an integer, it's used directly as the internal ID; otherwise, the value is looked up in NetSuite to find the corresponding internal ID for the trade type.

Contact Email

srcOrder.ConsumerEmail or srcOrder.ContactPerson?.Email

Mapped to a custom field specified by the Sales order email custom field name setting. Prioritizes consumer email, then contact person email.

Sales Representative Email

Sales Representative's Email

Mapped to a custom field specified by the Sales order sales rep email custom field name setting. The email is retrieved from the SalesRepsContext.

Order Source

srcOrder.Source

Mapped to a custom field specified by the Map order source to custom field setting.

Received By

Sales order received by custom field value setting or srcOrder.Salesrep

Mapped to a custom field specified by the Sales order received by custom field name setting. Uses the configured custom field value first, otherwise defaults to the sales representative's ID.

Delivery Date

srcOrder.OrderDate

Mapped to a custom field specified by the Sales order delivery date custom field name setting. The date is formatted as yyyyMMdd by default, or according to the Sales order delivery date custom field format setting if provided.

Special Logic & Filters

  • Default Order Type: If no specific order type is provided in order.OrderType?.ValueToBackoffice, the default order type used is 'SalesOrder'.

  • Shipping Address Selection: The system attempts to use an alternate address first. If not available, it prioritizes the main delivery address from the customer's addresses. If an external ID is present for the address, it is used to reference an existing NetSuite address. Otherwise, a new address record is created in NetSuite.

  • Billing Address Selection: If the Use visit address as invoice for orders setting is enabled, the system tries to use the main visit address from the customer's addresses as the billing address. Similar to shipping address, an existing NetSuite address is referenced if an AddressId is available; otherwise, a new one is created.

  • Trade Type Lookup: When mapping the Trade Type custom field, if the value from the custom data is not a numeric ID, the connector performs a lookup in NetSuite using the custom field's name to obtain its internal ID.

Domain Specifics / Extension Section

Order Header Logic

The order header is constructed using a combination of direct mappings from the App4Sales order object, hardcoded values (e.g., pending approval status), and values derived from connector settings and customer-related data. Special attention is given to linking the order to the correct customer entity and subsidiary within NetSuite. Payment terms are applied based on customer settings or a configurable default. Shipping and billing addresses are carefully selected and either referenced by existing IDs or created dynamically based on the provided App4Sales address details.

Line & Pricing Logic

Each order line is created as a SalesOrderItem in NetSuite. The item is referenced by its internal ID. The quantity is directly mapped. Pricing on the line can be set as a custom amount (calculated as quantity multiplied by the App4Sales line price) if the connector is configured to allow custom prices or if the order originates from a backoffice system. A default location can be assigned to each line if specified in the connector settings.

Charges & Attachments

At this stage of analysis, no explicit code has been identified within the SalesOrderHandler.cs for handling separate charge lines or attachments. This suggests that additional charges (like freight or payment fees) and attachments (PDFs, images) are either handled in a different part of the connector, or not directly supported by this specific NetSuite sales order creation process.

Responses & Error Handling

Upon successful creation of the sales order in NetSuite, the internal transaction ID (tranId) assigned by NetSuite is captured and returned. This ID is then used to update the corresponding order in the App4Sales database. In case of any exceptions during the order sending process (e.g., missing mandatory fields, API errors), an error message is logged, and a generic error string concatenated with the exception message is returned.

Related Settings & Prerequisites

  • Leave ship date empty: (Boolean) If enabled, the shipDate field in NetSuite sales order will be left empty.

  • Set Your Reference to PO number: (Boolean) If enabled, the App4Sales YourReference field will be mapped to NetSuite's otherRefNum. Requires YourReference to be non-empty if enabled.

  • Default payment condition ID for orders: (Text) The internal ID of the default payment terms to use for orders if the customer does not have a specific payment condition code.

  • Use visit address as invoice for orders: (Boolean) If enabled, the customer's main visit address in App4Sales will be used as the billing address in NetSuite.

  • Default location ID: (Text) The internal ID of the default location to associate with order lines and, if applicable, the order header in NetSuite.

  • Contact custom field name: (Text) The script ID of the custom field in NetSuite designated for storing the App4Sales contact person's ID.

  • Order bool custom field name: (Text) A comma-separated list of script IDs for custom boolean fields in NetSuite that should be set to true for the order.

  • Trade type custom field name: (Text) The script ID of the custom field in NetSuite designated for storing the order's trade type.

  • Sales order email custom field name: (Text) The script ID of the custom field in NetSuite designated for storing the contact's email address.

  • Sales order sales rep email custom field name: (Text) The script ID of the custom field in NetSuite designated for storing the sales representative's email address.

  • Map order source to custom field: (Text) The script ID of the custom field in NetSuite designated for storing the App4Sales order source.

  • Sales order received by custom field name: (Text) The script ID of the custom field in NetSuite designated for storing who received the order.

  • Sales order received by custom field value: (Text) The value to be stored in the 'Received By' custom field. If empty, the sales representative's ID will be used.

  • Sales order delivery date custom field name: (Text) The script ID of the custom field in NetSuite designated for storing the order's delivery date.

  • Sales order delivery date custom field format: (Text) The format string to apply when mapping the delivery date to the custom field (e.g., yyyyMMdd). If empty, yyyyMMdd is used as default.

  • Can use custom prices: (Boolean) Controls whether custom pricing is allowed for order lines in NetSuite.

  • Set Class for Sales Order Based on Passed Order Type: (Boolean) If enabled, the class field in NetSuite sales order will be populated from custom data based on the order type.

Known Limitations

  • No explicit code for handling separate charge lines or attachments has been identified within the SalesOrderHandler.cs for the sales order creation process.

  • If Set Your Reference to PO number is enabled and YourReference is empty, the order sending will fail.

  • The system assumes DeliveryDate is supplied; no default is applied if Sales order delivery date custom field name is set.

Did this answer your question?