FTP Connector - ItemUpdate
Overview
This function synchronizes item data and item filter data from CSV files located on an FTP server to the App4Sales platform. It updates item details, sales prices (including support for multiple price lists), item classes, and item class values. The synchronization runs based on the connector's update schedule.
Data Source Configuration
The connector downloads two CSV files from the configured FTP server:
items.csv: Contains the main item data.itemFilters.csv(orAssortiment.csvas a fallback): Contains item classification data, used to create Item Classes and Item Class Values.
Both files are expected to be semicolon (;) delimited and use UTF-8 encoding. Trailing semicolons in lines are automatically removed. If Settings.UseCsvItemSyncLogic is enabled, the files are processed through a streamlined internal CSV reader. If disabled, an older processing logic is used. Authentication details (username, password, host, port, and security protocol like SFTP, TLS, or SSL) are configured in the connector settings.
Data Mapping Table (Item)
App4Sales Field | Source Field (CSV Column in items.csv) | Logic/Notes |
|
| Direct mapping. Items with empty |
|
| Converted to decimal. If not present, defaults to 0. |
|
| If empty, defaults to "EUR". Otherwise, direct mapping. |
|
| Converted to decimal. If empty or 0, defaults to 1. |
|
| Converted to decimal. |
|
| Direct mapping. Trailing/leading whitespace is trimmed. |
|
| Converted to decimal. |
|
| Converted to char. '1' is mapped to 'I' (Included), '0' to 'E' (Excluded). Other invalid values default to 'E'. Value is converted to uppercase. |
|
| Direct mapping. |
|
| Direct mapping. |
|
| Direct mapping. |
|
| Direct mapping. |
|
| Direct mapping. (Only used if |
|
| Direct mapping. |
|
| Direct mapping. |
|
| Converted to integer. (Only used if |
|
| If |
|
| Converted to decimal. If 0, it's set to null. |
|
| Parsed as DateTime in "yyyy-MM-dd" format. Can be null. |
|
| Parsed as DateTime. If parsing fails, defaults to current date/time. |
| Derived | Calculated by the system based on |
| Derived | An |
Data Mapping Table (Item Prices)
App4Sales Field | Source Field (CSV Column in items.csv) | Logic/Notes |
| Derived from | Dynamically created based on the numeric suffix of |
| Derived from | Same as |
| Derived from | "PriceList X" where X is the numeric suffix from |
|
| Links the price to the item. |
|
| Value from |
| Derived from | Links the price to the dynamically created price list. |
Note: When Settings.UseCsvItemSyncLogic is disabled, default price lists (Default, Pricelist 2, Pricelist 3, Pricelist 4) are hardcoded with IDs 1, 2, 3, 4 respectively. salesprice2, salesprice3, and salesprice4 columns map directly to these hardcoded price lists.
Data Mapping Table (Item Filters - ItemClass and ItemClassValue)
App4Sales Field | Source Field (CSV Column in itemFilters.csv or Assortiment.csv) | Logic/Notes |
|
| The first non-empty column value is used as the Item Class name. Only item filters linked to existing item codes are processed. |
| Derived | If the Item Class is new, the ID is generated as a hash of its name. Otherwise, an existing ID is used. |
|
| Links the item class value to the item. |
|
| The first non-empty column value is used as the Item Class Value. If all are empty, it defaults to "Ja". |
| Derived from the Item Class Name | Links the item class value to its parent item class. |
|
| Direct mapping. |
Special Logic & Filters
Conditional Sync Logic: The connector uses
Settings.UseCsvItemSyncLogicto switch between an older and newer item synchronization method. The newer method (PerformNewCsvItemSyncLogic) processes files via streams and delegates to baseCsvConnectormethods (DoItemUpdate,DoItemFiltersUpdate). The older method (PerformOldCsvItemSyncLogic) processes the CSV files directly within the FTP connector and performs direct data updates.Data Cleanup: If
Settings.CleanDatais enabled and the new item sync logic is used, the following tables are truncated (all existing data deleted) before new item data is imported:itemclassvalues,itemclasses,items,itemprices,pricelists. This is a destructive operation.Error Handling: Exceptions during file download or processing are logged, and the synchronization process for the affected file may be aborted.
Script Execution: Pre- and post-update scripts (Jint scripts) can be executed for items, price lists, and item prices using
BindingFactory<IScriptingService>.Instance.ExecuteScript.SQL Overflow Prevention: Before updating items in the database, the system checks decimal properties (SalesPrice, PurchasePackageSize, VatPercentage, LastAvailableStock, MinimumOrderQuantity) to prevent SQL arithmetic overflows based on their defined precision and scale. Items causing an overflow are logged and removed from the update batch.
Domain Specifics (Expanded)
Price Logic
The system supports dynamic price lists. Any column in items.csv named salespriceX (where X is a number) will automatically create a new price list with ID X and description "PriceList X". The value in this column will be associated with the corresponding item and price list. If Settings.UseCsvItemSyncLogic is disabled, price lists are pre-defined as Default (1), Pricelist 2 (2), Pricelist 3 (3), and Pricelist 4 (4), with corresponding salespriceX columns mapping to these fixed IDs.
Item prices that are identical to the default sales price of an item are typically filtered out to reduce data redundancy, unless they belong to an "Action Price List" linked to a customer.
Image Handling
The ItemUpdate method itself does not directly handle image files from the FTP. However, it passes FTP connection details to the session settings, implying a separate process (likely a picture sync) uses these settings to download item pictures. The UpdateItemPictures method (in CsvConnector) processes item pictures from a stream (likely a ZIP archive) containing .jpeg, .jpg, and .png files. Images are resized, hashed, and stored in the database. Filenames are used to derive ItemCode and Sequence for linking images to items.
Stock & Availability
The LastAvailableStock column from items.csv is directly mapped. An additional item class "In stock" is automatically generated based on whether LastAvailableStock is greater than 0.
Matrix & Attributes
Item Classes and Item Class Values are primarily created from the itemFilters.csv (or Assortiment.csv) file. The system dynamically creates or updates Item Classes based on the content of these files, linking them to specific item codes. The logic for deriving the class name and value is flexible, using a precedence order of several CSV columns (e.g., ItemClass, FilterName, Value, FilterValue).
Free item fields are processed from the FreeItemFields or freefields column in items.csv and converted into an XML format, with behavior influenced by the Settings.UseDeprecatedFreeFieldsFormat setting.
Related Settings & Prerequisites
UseSFTP: Determines whether SFTP (secure) or standard FTP is used for file transfers.UseTLS: Enables TLS encryption for FTP.UseSSL: Enables SSL encryption for FTP.UseCsvItemSyncLogic: Boolean flag to switch between the old and new item synchronization logic.CleanData: If true, item- related tables (itemclassvalues, itemclasses, items, itemprices, pricelists) are truncated before import (only for new sync logic).UseDeprecatedFreeFieldsFormat: Affects how theFreeItemFieldscolumn is parsed and converted to XML.HideFreeFieldCaption: If true, the caption for free fields will be hidden in the generated XML.ReplaceLineFeedsWith: (Mentioned inSendOrderToBackoffice, but relevant for any multiline text fields). Specifies how line feeds should be replaced in multiline text fields (e.g., notes).UseStockIndicatorFromConnector: If true, the stock indicator for an item is taken directly from the connector's data rather than being calculated by App4Sales.FTP Server Access: Configured FTP host, username, and password in the connector administration.
File Paths: The connector expects
items.csvanditemFilters.csv(orAssortiment.csv) to be present in the root of the configured FTP folder.
Known Limitations
The
ItemUpdatemethod itself does not directly handle image file processing; it relies on a separate picture synchronization process.If
Settings.UseCsvItemSyncLogicis true, theitemFilters.csvfile is read twice, once via theUpdateSourcemechanism and once directly byUpdateItemFilters. While functionally correct, this could be inefficient.Items with decimal values that would cause SQL arithmetic overflow for specific database column definitions will be skipped during synchronization.
Item Class descriptions are truncated to 50 characters before being used to find or create item classes.