Scripts and counters
Control style codes, SKUs, barcodes and document numbers.
When you create a product or item without a style code, SKU or barcode, Smooth POS fills it in for you. Scripts decide what style codes and SKUs look like, and Counters supply the running numbers behind them, along with your barcodes and document numbers. You'll find both in Company Settings.
Scripts
Company Settings › Scripts has two editors:
| Script | Runs when | $ holds |
|---|---|---|
| Product Style Format | A product is created with no style code. | $.product_counter (the next product number) and $.product (the product being created). |
| Item SKU Format | An item is created with no SKU. | $.product and $.item (the item being created). |
Each script is a JavaScript expression. Smooth POS runs it and uses its value as the style code or SKU. It isn't a function: don't wrap it in function () { ... } or use return, just write the expression.
The defaults
The default Product Style Format turns the product counter into a 7-digit style code:
1000000 + $.product_counterSo product 42 gets style 1000042.
The default Item SKU Format builds the SKU from the style and the first two options, joined with hyphens:
$.product.style + ($.item.option1 != '' ? '-' + $.item.option1 : '') + ($.item.option2 != '' ? '-' + $.item.option2 : '')So a T-shirt with style 1000042, option 1 Red and option 2 M gets SKU 1000042-Red-M.
Examples
A style code with a prefix and a padded number, like TS-000042:
'TS-' + ('000000' + $.product_counter).slice(-6)A SKU in upper case with spaces removed, like 1000042-NAVYBLUE-XL:
[$.product.style, $.item.option1, $.item.option2, $.item.option3]
.filter(function (x) { return x; })
.join('-')
.toUpperCase()
.replace(/\s+/g, '')The last line's value is the result, so a multi-line expression works as long as it ends with the value you want.
Test before you saveA broken Item SKU Format script stops new products from being created, and a broken Product Style Format script leaves new products without a style code. Make your change, create one test product with an item, check its style code and SKU, then carry on.
Scripts only fill in blanks. A style code or SKU you type in, or send through the API, is always kept as it is.
Counters
Company Settings › Counters shows each counter and the last number it gave out. Every company has a set of counters from the start.
| Counter | Used for |
|---|---|
| Barcode Prefix | The start of every barcode Smooth POS makes. See below. |
| Barcode Counter | The running number in new barcodes. |
| Product Counter | $.product_counter in the Product Style Format script. |
| Invoice Counter | Invoice numbers. |
| Purchase Order Counter | Purchase order numbers. |
| POS Code Counter | POS codes. |
| Journal Counter | Journal numbers. |
Each counter holds the last number used, so the next one issued is that value plus 1. To start new products from 5000, set Product Counter to 4999 and select Update beside it.
Don't wind a counter backSetting a counter lower than it is now makes Smooth POS hand out numbers it has already used, which gives you duplicate style codes, barcodes or document numbers.
Barcodes
When an item is created without a barcode, Smooth POS makes an EAN-13 barcode for it:
- It takes your Barcode Prefix.
- It adds the next Barcode Counter value, padded with zeros so the two together are 12 digits.
- It adds the EAN-13 check digit.
For example, with prefix 930000000 and counter value 42, the first 12 digits are 930000000042, and the barcode is 9300000000422.
If you have a GS1 company prefix, use it as your Barcode Prefix, like 9312345. Your barcodes are then registered to you, and scan correctly with suppliers and marketplaces.
Keep the prefix and counter inside 12 digitsSmooth POS doesn't check that the prefix and counter fit. A 7-digit prefix leaves 5 digits for the counter, so 99,999 barcodes. Past that, or with a prefix of 12 digits or more, the barcodes stop being valid EAN-13s. Plan your prefix length for the number of items you expect.
Updated about 23 hours ago
