Skip to main content

Best Practices

Attribute Keys

Use keys with attributes whenever possible.
It is recommended to use getByKey for attributes, keys are static values.q Especially when you use Expivi with multiple languages, attribute names are localized values that change based on the active language in the configurator. You can add keys to attributes in the attributes overview of your product in the Backoffice.

Spreadsheets Connectors

Keep spreadsheet table structures and names the same between updates.
Because the result of rangeToArray is index-based, changing the order of columns can break your script.

HTTP Connectors

Ensure the speed of your script.
The Script Engine scripts are frequently executed to do real-time calculations for SKUs or pricing for the configurator. It is important that these calculations are fast, to avoid blocking the customer from seeing the correct price or blocking the add-to-cart process. Using HTTP Connectors in your script will increase execution time, so it is important that these endpoints respond as fast as possible.

Clean Code

Script engine scripts allow you to write any kind of Javascript code to calculate either the SKU or pricing. There is a lot of freedom in what you can do in these scripts, which might lead to bad or inefficient code. We highly recommend keeping the scripts clean and easy to read.

There are a couple of rules you could follow to help you write good code:

  • Remove unused code.
  • Group code the code in parts, for example.
    1. The first part is for preparation, gathering the data from attributes and or preparing connectors.
    2. The second part can be gathering the data that is essential for the calculations.
    3. The third part will do the calculations and return the data.
  • Describe your variables/data plainly to avoid confusion.
  • Try reusing data or functions as much as possible to avoid duplicating code and keep the code small and efficient.