StyleMan Connector - SendOrderToBackoffice
This function transmits an App4Sales order to the StyleMan ERP system. It orchestrates the conversion of App4Sales order data (including header and lines) into a format suitable for the StyleMan REST API and sends it for processing. The function performs validation checks and, if successful, updates the App4Sales order with the ERP-provided order number. This process is triggered when an order is sent from App4Sales to the back office.
Data Source Configuration
The primary data source is the App4Sales Order object, which encapsulates all order-related information. The target is the StyleMan REST API, specifically the /Orders endpoint, used with an HTTP POST method to create new orders in the ERP. Authentication is handled by the connector's base framework.
Domain Specifics
Order Header Logic
The ConvertToEntity method maps various fields from the App4Sales Order and Customer objects to the SalesOrder entity for the REST API. Key fields include order ID, customer information, timestamps, notes, references, and totals. It also handles the order type and alternative delivery addresses based on specific settings. The sales representative's warehouse is also included.
Order Header Mapping
App4Sales Field | Source Field (API/Excel/DB) | Logic/Notes |
Order ID (GUID) |
| Passed directly from App4Sales. |
Order Number |
| App4Sales internal order number. |
Customer GUID |
| Unique identifier for the customer. |
Customer Code |
| Customer's alphanumeric code. |
Created Date |
| Timestamp of when the order entity is created for the API call. |
Order Date |
| Date of the order in App4Sales. |
Is Open |
| Hardcoded as |
Notes |
| General notes associated with the order. |
Description 1 |
| Additional description field 1. |
Description 2 |
| Additional description field 2. |
Description 3 |
| Additional description field 3. |
Reference |
| General reference for the order. |
Subtotal (Excl. VAT) |
| Calculated total amount excluding VAT. |
Total Amount |
| Total amount of the order (incl. VAT). |
VAT Total |
| Total VAT amount for the order. |
Your Reference |
| Customer's reference. |
Username |
| Username of the sales representative who created the order. |
Warehouse |
| Warehouse associated with the sales representative (if available). Retrieved from |
Signature |
| Digital signature associated with the order. |
Delivery Method Code |
| Code of the selected delivery method. |
Order Type |
| Value from the order type configuration, sent only if |
Delivery Address |
| If an |
Delivery Address ID |
| GUID of the alternative delivery address, if provided and valid. Otherwise, |
Line & Pricing Logic
Each App4Sales OrderLine is converted into a RestJsonSalesEntryLine for transmission to the ERP. The conversion involves mapping item codes, quantities, prices, and discounts. It also calculates PriceIncl based on PriceExcl and VatPercentage. A defaultPrice and customerDiscount are passed to the conversion method, which can influence how pricing is handled, especially for discount calculations. The line number is assigned sequentially.
Order Line Mapping
App4Sales Field | Source Field (API/Excel/DB) | Logic/Notes |
Line ID |
| A new GUID is generated for each order line. |
Customer GUID |
| Unique identifier of the customer (passed from the order header). |
Discount |
| Discount percentage applied to the line. |
Total Discount |
| Total discount amount from the original price. |
Item Code |
| Code of the item on the order line. |
Quantity |
| Ordered quantity. |
Quantity Delivered |
| Quantity that has already been delivered. |
VAT Percentage |
| VAT percentage of the item. |
Price Excl. VAT |
| Unit price excluding VAT. |
Price Incl. VAT |
| Calculated unit price including VAT. |
Default Price |
| Default price of the item, obtained from |
Line Number |
| Sequential line number within the order. |
Instruction |
| Specific instructions for the order line. |
Item Description |
| Description of the item. |
Delivery Date |
| Expected delivery date for the line. Only sent if value is present. |
Charges & Attachments
This connector does not explicitly support separate "charge lines" (e.g., freight, payment fees) or "attachments" (e.g., PDF, XML documents) as distinct entities when sending an order to the StyleMan ERP via the SalesOrder API.
Surcharges: Any surcharges or additional fees must be factored into the
SubTotal,Total, andVatTotalfields of the order header, or potentially represented as regular order lines with specific item codes if the ERP supports this.Attachments: Explicit document attachments (like PDFs or custom XML payloads) are not directly transmitted through the
SalesOrderstructure. Information related to attachments may be conveyed indirectly via fields likemodel.Notes,model.Description1,model.Description2,model.Description3, ormodel.Reference. Themodel.Signaturefield captures a digital signature associated with the order.
Responses & Error Handling
Upon successful submission of an order to the StyleMan ERP, the connector expects an SalesOrder object in response.
Successful Response: If the response contains an
OrderNumber, this number is used to update the corresponding order within App4Sales' internal database viaOrdersContext.Instance.UpdateOrderNumber. The ERP's order number is then returned as the result of theSendOrderToBackofficefunction.Duplicate Order Detection: If
Settings.ValidateOrderBeforeSendingis enabled, the connector first checks if an order with the sameOrderID(App4Sales internal GUID) already exists in the ERP by querying theRoutes.Ordersendpoint with a filter. If a matching order number is found, it updates the App4Sales order with the existing ERP number and prevents re-sending.Error Handling:
RestException: Catches REST-specific errors. The error message from the exception (ex.GetErrorMessage()) is returned to App4Sales, prefixed withConstants.Error.ERROR.RequestException: Catches errors related to HTTP requests (e.g., network issues, invalid URLs). The exception's message is returned, prefixed withConstants.Error.ERROR.General
Exception: Catches any other unexpected errors during the process. The exception's message is returned, prefixed withConstants.Error.ERROR.
Missing Order Number: If the ERP response does not contain an order number (e.g.,
response?.Numberis null or empty), the function returns a generic error message:Constants.Error.ERROR + "No order number retrieved from backoffice".
Related Settings & Prerequisites
Filter non-ISO-8859-1 Characters (
FilterNonIso88591Characters):Description: When enabled, this setting removes any characters from the order details that are not part of the ISO-8859-1 character set before sending the order to the back office.
Impact: Ensures compatibility with ERP systems that may have strict character encoding requirements.
Validate Order Before Sending (
ValidateOrderBeforeSending):Description: If this setting is active, the connector will query the ERP system to check if an order with the same internal App4Sales ID already exists.
Impact: Prevents the creation of duplicate orders in the ERP if an order was previously sent but App4Sales did not receive a confirmation (e.g., due to a network issue). If a duplicate is found, the existing ERP order number is used, and the order is not re-sent.
Use Results Tag For Request (
UseResultsTagForRequest):Description: This setting alters the structure of the JSON payload sent to the ERP for order creation.
Impact: If enabled, the
SalesOrderobject is wrapped withinBaseResponse2andBaseResponseobjects, indicating a specific API expectation for the request format. If disabled, theSalesOrderobject is sent directly. This setting is specific to the ERP's API design.
Do Not Send Alternative Address On Order (
DontSendAlternativeAddressOnOrder):Description: When enabled, this setting prevents the alternative delivery address specified in App4Sales from being sent with the order to the ERP system.
Impact: If an alternative delivery address is present in the App4Sales order and this setting is
false, the alternative address details will be included in theDeliveryAddresssection of theSalesOrderpayload sent to the ERP. Iftrue, the alternative address is omitted.