f(x) Attributes - Technical Documentation
Overview
f(x) attributes enable the automatic calculation and updating of product attributes using JavaScript code.
The system executes scripts whenever product changes occur and automatically stores the calculated values.
Functional attributes are available for the following attribute types:
Functionality
JavaScript Execution
The system uses a Java-based JavaScript engine for script execution with the following steps:
-
Initialization: Creating the execution context
-
Provisioning: Access to product data through predefined variables
-
Calculation: Execution of the calculation logic
-
Persistence: Automatic saving of the result
Multilingual Support
Language-Dependent f(x) Attributes
If an f(x) attribute is configured as language-dependent, the script is executed separately for each activated language.
Example:
// These values change depending on the language run:
var articleName = product.get("articleName");
// DE: "Artikel", EN: "Article"
var description = product.get("description");
// DE: "Beschreibung...", EN: "Description..."
// This value always remains the same:
var articleNumber = product.get("articleNumber");
// Always: "12345"
// Calculation uses the values of the current language
result = articleName + " (" + articleNumber + ")";
Execution Flow for 3 Languages (DE, EN, FR):
-
Run DE:
-
Language-dependent attributes → German values
-
Language-independent attributes → Default value
-
Result is stored for DE
-
-
Run EN:
-
Language-dependent attributes → English values
-
Language-independent attributes → Default value
-
Result is stored for EN
-
-
Run FR:
-
Language-dependent attributes → French values
-
Language-independent attributes → Default value
-
Result is stored for FR
-
Limitations
-
What works:
-
Reading language-dependent values of the current language
-
Calculating language-dependent results
-
Producing different results per language
-
-
What does not work:
-
Querying values of another language inside the script
-
Determining the current language ID inside the script
-
Cross-language calculations (e.g. combining DE + EN values)
-
| The script is language-agnostic - it does not know which language is currently being processed, but it automatically receives the correct language-specific values. |
Dirty Processing Workflow and Status Transitions
The system uses a status-based processing workflow to ensure that calculated attributes are always up to date.
Status Overview
READY
-
Product is fully updated
-
All f(x) scripts have been executed successfully
-
Attribute values are consistent
Workflow Process
-
Change Detection: When a product attribute changes, the system automatically checks whether dependent f(x) scripts exist
-
Status Transition to DIRTY_WAITING: The product is marked for processing
-
Automatic Processing: A background process detects waiting products and starts calculation
-
Status Transition to DIRTY_PROCESSING: During active script execution
-
Script Execution: All f(x) scripts of the product are executed sequentially
-
Value Persistence: Calculated values are automatically stored
-
Status Transition to READY: Processing complete, product is up to date
|
Update Timestamp With every script execution, the product modification timestamp is updated - even if the calculated attribute value does not change. This ensures that downstream systems are informed about the recalculation and can react accordingly. |
Use Case Examples
Example 1: Dynamic Product Categorization
Scenario: Automatic assignment of a shipping category based on product properties
// Read product properties
var weight = product.get("weight");
var dimensions = product.get("dimensions");
// Categorization logic
if (weight > 30 && dimensions > 100) {
result = "Bulky Goods";
} else if (weight > 10) {
result = "Parcel Shipping";
} else {
result = "Standard Shipping";
}
Flow:
-
Weight attribute is changed from 8kg to 35kg
-
Status switches to DIRTY_WAITING
-
System starts processing
-
Status switches to DIRTY_PROCESSING
-
Script checks conditions and determines "Bulky Goods"
-
Shipping category is stored
-
Status switches to READY
-
Product is marked as updated for downstream systems
Example 2: Availability Status
Scenario: Calculation of product availability based on stock level and delivery lead time
var stock = product.get("stockQuantity");
var leadTime = product.get("deliveryLeadTime");
if (stock > 0) {
result = "Available Immediately";
} else if (leadTime <= 7) {
result = "Available in " + leadTime + " days";
} else {
result = "On Request";
}
Flow:
-
Stock level is reduced from 5 to 0
-
Status switches to DIRTY_WAITING
-
Processing starts automatically
-
Status switches to DIRTY_PROCESSING
-
Script calculates new availability status based on lead time
-
Status text is updated
-
Status switches to READY
-
Modification timestamp is updated (even if text remains unchanged)
Example 3: Multilingual Product Name
Scenario: Automatic generation of a complete product name from multiple language-dependent attributes
var brand = product.get("brand");
var model = product.get("modelNumber");
// language-independent
var color = product.get("color");
// language-dependent
var size = product.get("size");
// language-independent
// Assemble full name
result = brand + " " + model + " - " + color + " (" + size + ")";
Execution Across 2 Languages:
-
Run DE:
-
brand: "Samsung"
-
model: "Galaxy S23" (always the same)
-
color: "Mitternachtsschwarz"
-
size: "256GB" (always the same)
-
Result DE: "Samsung Galaxy S23 - Mitternachtsschwarz (256GB)"
-
-
Run EN:
-
brand: "Samsung"
-
model: "Galaxy S23" (always the same)
-
color: "Midnight Black"
-
size: "256GB" (always the same)
-
Result EN: "Samsung Galaxy S23 - Midnight Black (256GB)"
-
Flow:
-
Color is changed from "Phantom White" / "Phantom Weiß" to "Midnight Black" / "Mitternachtsschwarz"
-
Status switches to DIRTY_WAITING
-
System starts processing
-
Status switches to DIRTY_PROCESSING
-
Script is executed for DE → German name is generated and stored
-
Script is executed for EN → English name is generated and stored
-
Status switches to READY
-
Modification timestamp is updated