SAPB1SL Connector - ItemUpdate
This function synchronizes item-related data from SAP Business One Service Layer (SAP B1 SL) to the App4Sales platform. It retrieves items, item groups, various item-specific attributes, stock information, and pricing data from SAP B1 SL, then processes and maps this information to the internal App4Sales data structures. The synchronization can be a full sync or a partial sync based on item update dates.
Data Source Configuration
The connector pulls data from the SAP Business One Service Layer (SAP B1 SL) API. The base URL and authentication details are configured within the connector settings. Item data is retrieved from the Item endpoint. Additionally, data is sourced from various other SAP B1 SL endpoints for related entities such as:
Item Groups: For categorizing items.
Discount Groups: For applying discount logic.
Item Properties: Custom properties defined in SAP B1 SL.
VAT Groups: For tax rate information.
Purchase Orders: To determine next delivery dates.
User-Defined Fields: Custom fields for items.
Item Brands, Product Types, Qualities, Mattresses, Versions, Colors, Item Statuses: These are retrieved if corresponding 'Item Free Field Names' are configured in the connector settings, acting as lookups for custom item attributes.
Product Trees (BOMs): Used for calculating stock for 'kit' or 'assembly' items.
Special Prices: For specific item pricing rules.
Data is generally pulled from SAP B1 SL using OData filters for partial synchronizations, based on the UpdateDate field.
Data Mapping Table: Item (Main Fields)
App4Sales Field | Source Field (API/Excel/DB) | Logic/Notes |
|
| Direct mapping from the SAP B1 SL Item Code. |
|
| Date when the item was created in SAP B1 SL. Converted from string to DateTime. |
|
| Date when the item was last updated in SAP B1 SL. Converted from string to DateTime. |
|
| Currency of the default item price, based on the price list defined in the "Price List Code For Default Item Price" setting. |
|
| Item name from SAP B1 SL. If the setting "Add Comment Field To Item Categories" is disabled, the item's |
|
| Foreign name of the item. |
|
| Barcode of the item. |
|
| Type of the item (e.g., 'Service', 'Inventory'). |
|
| If the "Last Available Stock Field" setting is specified, this field attempts to retrieve a value from a dynamic item property or unknown element with that name. Otherwise, it defaults to the item's |
|
| The default sales price of the item, obtained from the price list specified in the "Price List Code For Default Item Price" setting. Defaults to 0 if not found. |
|
| The item's sales unit. |
| Hardcoded | Always set to 'E'. |
|
| If a sales VAT group is assigned and has VAT lines, the percentage is taken from the most recently effective VAT line (based on |
|
| If the "Item Property For Purchase Package Size" setting is specified, the value is retrieved from the corresponding dynamic item property or unknown element. The value must be parsable as a decimal. |
| Derived from | If "Item Groups Names For Related Items" setting is configured and the current item's |
| Derived from | If the "Use Next Delivery Date from Purchase Order" setting is enabled and a next delivery date is found for the item, that date is used. Otherwise, the system searches open purchase order lines for the item, looking for the earliest future |
|
| If the "Item Status Field" setting is specified, the value is retrieved from the specified dynamic item property. If "Use Endpoint To Retrieve Item Status Description" is also true, the descriptive name from the SAP B1 SL Item Status endpoint is used; otherwise, the raw property value is mapped. |
Data Mapping Table: Item Categories (Dynamic Attributes)
The ItemCategories field in App4Sales stores a dictionary of flexible attributes. Values are added to this dictionary if they are not null or empty.
App4Sales Field (Key) | Source Field (API/Excel/DB) | Logic/Notes |
|
| Name of the item group the item belongs to. |
|
| Item length, converted to invariant culture string. |
|
| Item height, converted to invariant culture string. |
|
| Item width, converted to invariant culture string. |
|
| Item volume, converted to invariant culture string. |
|
| Item weight, converted to invariant culture string. |
|
| Minimum order quantity, converted to invariant culture string. |
|
| Shipping type, converted to invariant culture string. |
|
| Sales VAT Group Code, converted to invariant culture string. |
|
| Sales Factor 1. |
|
| Sales Factor 2. |
|
| Sales Factor 3. |
|
| Sales Factor 4. |
|
| Manufacturer name, converted to invariant culture string. |
|
| Item comment. |
|
| Values from item attribute groups (e.g., Attribute1 to Attribute64) are mapped if present. |
Dynamic Item Properties |
| All key-value pairs from |
|
| If "Price List Code For Recommended Market Price" setting is configured, the corresponding price from the item's price list is mapped. |
Unknown String Elements |
| Any other unknown string-compatible elements found in the SAP B1 SL item data are added as categories. |
| Dynamic field named by "Item Free Field Name For Brand", then mapped to | If "Item Free Field Name For Brand" is set, the value from this field in SAP B1 SL is used as a code to look up the brand's descriptive name. |
| Dynamic field named by "Item Free Field Name For Color", then mapped to | If "Item Free Field Name For Color" is set, the value from this field in SAP B1 SL is used as a code to look up the color's descriptive name. |
| Dynamic field named by "Item Free Field Name For Type", then mapped to | If "Item Free Field Name For Type" is set, the value from this field in SAP B1 SL is used as a code to look up the product type's descriptive name. |
| Dynamic field named by "Item Free Field Name For Status", then mapped to | If "Item Free Field Name For Status" is set, the value from this field in SAP B1 SL is used as a code to look up the item status's descriptive name. |
| Dynamic field named by "Item Free Field Name For Mattress", then mapped to | If "Item Free Field Name For Mattress" is set, the value from this field in SAP B1 SL is used as a code to look up the mattress type's descriptive name. |
| Dynamic field named by "Item Free Field Name For Quality", then mapped to | If "Item Free Field Name For Quality" is set, the value from this field in SAP B1 SL is used as a code to look up the quality's descriptive name. |
| Dynamic field named by "Item Free Field Name For Version", then mapped to | If "Item Free Field Name For Version" is set, the value from this field in SAP B1 SL is used as a code to look up the version's descriptive name. |
Data Mapping Table: Item Stock
App4Sales Field | Source Field (API/Excel/DB) | Logic/Notes |
|
| For product trees, this is the minimum 'Shelf Stock' of its components divided by the component quantity in the bill of materials. For standard items, if "Warehouse Codes For Stock" is specified, it sums either |
|
| For product trees, it is |
|
| For product trees, this is the minimum 'To Be Received' of its components divided by the component quantity in the bill of materials. For standard items, if "Warehouse Codes For Stock" is specified, it sums |
Custom Last Available Stock | Dynamic field named by "Last Available Stock Field" | If "Last Available Stock Field" is configured, its value from a dynamic property or unknown element is added to the stock information. |
Data Mapping Table: Item Group Links
App4Sales Field | Source Field (API/Excel/DB) | Logic/Notes |
|
| The numerical code of the item group. |
|
| The item code. |
Data Mapping Table: Price List Prices
App4Sales Field | Source Field (API/Excel/DB) | Logic/Notes |
|
| The ID of the price list from SAP B1 SL. |
|
| The item code. |
|
| The price of the item in the specific price list. |
|
| The discount percentage applied to the item, calculated based on SAP B1 SL Discount Groups if "Include All BPs Discount Groups Discounts Into Item Prices" is enabled. |
Data Mapping Table: Staffle Prices (Tier Prices)
App4Sales Field | Source Field (API/Excel/DB) | Logic/Notes |
|
| The customer code to whom this special price applies. |
|
| The item code for which this special price applies. |
|
| The special price for the item. |
|
| The price list ID to which this special price belongs. |
|
| Discount percentage from SAP B1 SL Discount Groups. This is populated if "Use Staffle Prices For Specific Discount Groups Discounts During Live Prices Get" is enabled, combining discounts from various levels (customer, item group, item). |
| Derived from Discount Groups | The minimum quantity for which the staffle price applies. |
| Derived from Discount Groups | The customer group for which the staffle price applies. |
Special Logic & Filters
Full vs. Partial Sync: The synchronization type (full or partial) is determined by the "Do Next Sync As Full Sync" setting or if the current day is Saturday. Partial syncs use the last synchronization date to filter items by
UpdateDatein SAP B1 SL.Item Exclusion: Items are excluded from synchronization if the "Exclude Invalid Items From Sync" setting is true and the item's
Validstatus in SAP B1 SL is 'False' or itsFrozenstatus is 'True'. These items are marked for deletion in App4Sales.Conditional Item Sync: If the "Check Item Property With Name For Item Sync" setting is configured, items will only be synchronized if the specified item property exists and its value is not empty or 'False'.
Item Category Exclusion: If the "Exclude Items From Sync Based On Item Category" setting is set, items whose categories match predefined 'YesValues' for that specific category are excluded from synchronization.
Discount Group Processing: If "Include All BPs Discount Groups Discounts Into Item Prices" is enabled, the system retrieves SAP B1 SL Discount Groups and calculates an item discount based on various rules (specific customer/item, specific customer/item group, customer group/item, customer group/item group, customer group/manufacturer). The lowest discount is applied if "Use Customer Discount Relation For Live Prices Discount Calculation" and the customer's discount relation is 'LowestDiscount'; otherwise, the highest discount is applied.
Stock Calculation (Product Trees): For items identified as product trees (Bill of Materials), stock is calculated recursively based on the minimum available stock of their components, adjusted by the component quantity in the product tree.
Stock Calculation (Warehouses): If "Warehouse Codes For Stock" are specified, stock values (ShelfStock, ToBeDelivered, ToBeReceived) are aggregated from the specified warehouses in SAP B1 SL.
Stock Calculation (In/On Stock): The "Use In Or On Stock As Shelf Stock And Stock Formula For Available Stock" setting determines whether
InStockorCountedvalues are used forShelfStockwhen specific warehouse codes are applied.Language Mapping for Descriptions: The
UpdateDescriptionLanguageMappingmethod maps a foreign language description (if "Foreign Item Description Language" is set) toDescriptionField = 2in App4Sales, with the default language mapping toDescriptionField = 1.Price List Updates: The
UpdatePriceListsmethod is called at the beginning of the ItemUpdate process to ensure that all relevant price lists from SAP B1 SL are synchronized to App4Sales.Staffle Prices Update: Special prices from SAP B1 SL are retrieved and converted into App4Sales
StafflePriceentities. Discount Groups can also contribute to the staffle prices if "Use Staffle Prices For Specific Discount Groups Discounts During Live Prices Get" is enabled.Database Updates: After processing, items, item group links, price list prices, and staffle prices are updated in the App4Sales internal database using
DatabaseManager.Instance.UpdateItems2,UpdateItemGroups,UpdatePriceListPrices, andUpdateStafflePricesrespectively.
Domain Specifics (Expanded)
Price Logic
The connector handles various pricing aspects, including a default sales price, recommended market prices, and dynamic discounts.
Default Sales Price: The primary sales price is derived from an item's price list in SAP B1 SL, specifically the one designated by the "Price List Code For Default Item Price" setting.
Recommended Market Price: If the "Price List Code For Recommended Market Price" setting is configured, an additional price from that specific price list in SAP B1 SL is retrieved and mapped as an item category.
Discount Groups: SAP B1 SL Discount Groups can influence item prices. When enabled via the "Include All BPs Discount Groups Discounts Into Item Prices" setting, the connector applies discounts based on a hierarchy of rules (customer-specific, item group-specific, customer group-specific). The calculation for whether the highest or lowest discount applies is determined by the customer's discount relation, if defined in a customer free field named 'DiscountRelation'.
Staffle Prices (Tier Prices): Special prices and volume-based discounts from SAP B1 SL are synchronized as App4Sales Staffle Prices. These can be specific to a customer, customer group, item, or item group, and can also be tied to specific price lists or apply to all customers.
Image Handling
(No direct image handling logic was observed within the ItemUpdate, GetItemsInfo, or ToItemDb methods. This typically implies image synchronization is handled by a separate process or module within the connector. If no images are explicitly linked or processed here, this section will remain brief.)
No explicit image handling logic was found within the analyzed methods. It is assumed that image synchronization is handled by a separate part of the connector or platform.
Stock & Availability
Stock information is a critical component of the item synchronization, with special considerations for product trees and multi-warehouse setups.
Stock Sources: Stock data originates from
SapB1SLItem.QuantityOnStock,SapB1SLItem.QuantityOrderedByCustomers,SapB1SLItem.QuantityOrderedFromVendors, andSapB1SLItem.ItemWarehouseInfoCollectionin SAP B1 SL.Multi-Warehouse Support: The "Warehouse Codes For Stock" setting allows administrators to specify a comma-separated list of SAP B1 SL warehouse codes. When specified, stock quantities are aggregated only from these designated warehouses.
Product Tree Stock: For items defined as product trees (Bill of Materials) in SAP B1 SL, the system recursively calculates the available
ShelfStockandToBeReceivedbased on the minimum stock of their individual components. The "Warehouse Codes For Product Trees" setting can be used to filter warehouses considered for product tree stock calculations.Shelf Stock Definition: The definition of
ShelfStockdepends on the "Use In Or On Stock As Shelf Stock And Stock Formula For Available Stock" setting and whether specific warehouse codes are used. It can be derived fromInStockorCountedquantities in SAP B1 SL.Last Available Stock: A custom stock field can be mapped using the "Last Available Stock Field" setting, allowing for flexible integration of additional stock metrics from SAP B1 SL.
Matrix & Attributes
The connector maps various item attributes and classifies items using item groups and configurable free fields.
Item Groups: The primary item grouping from SAP B1 SL is mapped.
Item Attributes (1-64): Standard item attributes defined in SAP B1 SL are mapped as item categories.
Dynamic Item Properties: All configured dynamic item properties from SAP B1 SL are mapped as item categories, providing flexibility for custom attributes.
Configurable Free Fields: The connector supports mapping custom attributes like Brand, Color, Product Type, Status, Mattress, Quality, and Version using configurable free field names (e.g., "Item Free Field Name For Brand"). These settings allow administrators to specify the SAP B1 SL field that holds the code for these attributes, which are then looked up against their respective descriptive endpoints in SAP B1 SL.
Derived Attributes: Attributes like Length, Height, Width, Volume, Weight, Min Order Quantity, Ship Type, Sales Factors, Manufacturer, and Comment are directly mapped as item categories from their corresponding SAP B1 SL fields.
Related Settings & Prerequisites
Price List Code For Default Item Price: (Required) Specifies the SAP B1 SL price list to use for determining the default item sales price and currency.
Add Comment Field To Item Categories: (Boolean) If disabled, the item's
Commentfield from SAP B1 SL is appended to the item's main description.Last Available Stock Field: (Optional) The name of a custom item property or user-defined field in SAP B1 SL that contains the 'Last Available Stock' value.
Item Property For Purchase Package Size: (Optional) The name of a custom item property or user-defined field in SAP B1 SL that contains the 'Purchase Package Size'.
Use Next Delivery Date from Purchase Order: (Boolean) If enabled, the system attempts to retrieve the next delivery date from SAP B1 SL purchase orders.
Warehouse Codes For Stock: (Optional) A comma-separated list of SAP B1 SL warehouse codes. If specified, stock calculations will only consider these warehouses.
Item Groups Names For Related Items: (Optional) A comma-separated list of SAP B1 SL item group names. Items within these groups will have other items from the same group listed as 'related items'.
Item Status Field: (Optional) The name of a custom item property or user-defined field in SAP B1 SL that contains the item's status.
Use Endpoint To Retrieve Item Status Description: (Boolean) If enabled, when "Item Status Field" is set, the connector attempts to retrieve the descriptive name of the item status from an SAP B1 SL endpoint.
Price List Code For Recommended Market Price: (Optional) Specifies an SAP B1 SL price list to use for a 'Recommended Market Price' which is mapped as an item category.
Exclude Invalid Items From Sync: (Boolean) If true, items marked as 'invalid' or 'frozen' in SAP B1 SL are excluded from synchronization and removed from App4Sales.
Check Item Property With Name For Item Sync: (Optional) If set, items will only be synchronized if the specified item property exists and its value is not empty or 'False'.
Exclude Items From Sync Based On Item Category: (Optional) Specifies an item category. Items whose value for this category matches predefined 'YesValues' will be excluded from synchronization.
Include All BPs Discount Groups Discounts Into Item Prices: (Boolean) If enabled, SAP B1 SL Discount Groups are used to calculate and apply discounts to item prices during synchronization.
Use Customer Discount Relation For Live Prices Discount Calculation: (Boolean) If enabled alongside discount group processing, a customer's 'DiscountRelation' free field (if present and 'LowestDiscount') influences whether the minimum or maximum discount from applicable discount groups is used.
Use Staffle Prices For Specific Discount Groups Discounts During Live Prices Get: (Boolean) If enabled, staffle prices are derived from discount groups.
Foreign Item Description Language: (Optional) Specifies a language code. If set, a second description field (Description2) will be mapped with the foreign language.
Use In Or On Stock As Shelf Stock And Stock Formula For Available Stock: (Boolean) Influences how
ShelfStockis calculated from SAP B1 SL warehouse data.Warehouse Codes For Product Trees: (Optional) A comma-separated list of SAP B1 SL warehouse codes. If specified, product tree stock calculations will only consider these warehouses.
Known Limitations
The image handling logic was not directly observed in the analyzed code paths, suggesting it may be external or handled differently.
Some discount group scenarios (e.g., specific customer & manufacturer discount, all customers & manufacturer/item group/item discounts) are noted as "TODO: missing" in the source code, indicating they are not currently covered.
The calculation for
ShelfStockwhen no specific "Warehouse Codes For Stock" are provided and "Use In Or On Stock As Shelf Stock And Stock Formula For Available Stock" is false defaultsShelfStockto 0, which might not be the intended fallback.