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 |
| Mapped to NetSuite's |
Customer |
| Mapped to NetSuite's |
Order Status | N/A | Hardcoded to |
Memo (Notes) |
| Mapped directly to NetSuite's |
Subsidiary |
| Determined by |
Sales Representative |
| Mapped to NetSuite's |
Customer PO Number |
| Mapped to NetSuite's |
Payment Terms |
| Mapped to NetSuite's |
Shipping Address |
| Mapped to NetSuite's |
Billing Address |
| Mapped to NetSuite's |
Class | Custom Data (Order Type value) | Mapped to NetSuite's |
Location |
| Mapped to NetSuite's |
Data Mapping Table (Order Lines)
App4Sales Field | Source Field (API/Excel/DB) | Logic/Notes |
Item |
| Mapped to NetSuite's |
Quantity |
| Mapped to NetSuite's |
Amount (Line Price) |
| Mapped to NetSuite's |
Line Location |
| Mapped to NetSuite's |
Custom Field Mappings (Order Header)
App4Sales Field | Source Field (API/Excel/DB) | Logic/Notes |
Contact Person |
| Mapped to a custom field specified by the |
Boolean Custom Fields | N/A | Custom boolean fields specified in the |
Trade Type | Custom Data (from order type) | Mapped to a custom field specified by the |
Contact Email |
| Mapped to a custom field specified by the |
Sales Representative Email | Sales Representative's Email | Mapped to a custom field specified by the |
Order Source |
| Mapped to a custom field specified by the |
Received By |
| Mapped to a custom field specified by the |
Delivery Date |
| Mapped to a custom field specified by the |
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 orderssetting 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 anAddressIdis 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
shipDatefield in NetSuite sales order will be left empty.Set Your Reference to PO number: (Boolean) If enabled, the App4Sales
YourReferencefield will be mapped to NetSuite'sotherRefNum. RequiresYourReferenceto 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
truefor 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,yyyyMMddis 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
classfield 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.csfor the sales order creation process.If
Set Your Reference to PO numberis enabled andYourReferenceis empty, the order sending will fail.The system assumes
DeliveryDateis supplied; no default is applied ifSales order delivery date custom field nameis set.