{"title":"scAction","slug":"pos-sc-action","url":"https://support.storeconnect.com/articles/pos-sc-action","url_markdown":"https://support.storeconnect.com/articles/pos-sc-action.md","subtitle":null,"summary":"The scAction global JavaScript function lets custom code in POS views and HTML templates trigger any POS action programmatically, with optional onSuccess and onError callbacks.","type":"Developer_Documentation","video_url":"","keywords":"POS, scAction, JavaScript, onSuccess, onError, callbacks, actions","last_modified":"2026-08-21T07:12:35+0000","body_markdown":"`scAction` is a global JavaScript function available in the POS. It lets custom code in POS views (Liquid templates rendered in the POS) and inline HTML trigger any POS action programmatically.\n\n## Signature\n\n```javascript\n\nscAction(action, params, options)\n```\n\n| Parameter | Type | Required | Description |\n|-----------|------|----------|-------------|\n| `action` | String | Yes | The action identifier (e.g. `'cart:add_product'`) |\n| `params` | Object | No | Key-value pairs of action parameters |\n| `options` | Object | No | Optional callbacks: `{ onSuccess, onError }` |\n\n### Options\n\n| Option | Type | Description |\n|--------|------|-------------|\n| `onSuccess` | Function | Called after the action and any chained actions complete successfully. |\n| `onError` | Function | Called with an `Error` if any link in the chain rejects — including a missing chained action. Also called synchronously when no `action` is provided. |\n\n## Usage\n\n### Adding a product to the cart\n\n```javascript\n\nscAction('cart:add_product', { product_code: 'SKU123', quantity: 2 })\n```\n\n### Starting checkout\n\n```javascript\n\nscAction('checkout:start')\n```\n\n### Opening a modal\n\n```javascript\n\nscAction('modal:open:url', { url: '/custom/page' })\n```\n\n### In a Liquid/HTML POS view\n\n\n```html\n\n\u003cbutton type=\"button\" onclick=\"scAction('cart:add_product', { product_id: '{{ product.sfid }}' })\"\u003e\n  Add to cart\n\u003c/button\u003e\n\n\u003cbutton type=\"button\" onclick=\"scAction('modal:close')\"\u003e\n  Close\n\u003c/button\u003e\n```\n\n\n### Reacting to success or failure\n\nPass `onSuccess` and/or `onError` to handle the outcome of the action:\n\n```javascript\n\nscAction(\n  'cart:add_product',\n  { product_code: 'SKU123', quantity: 1 },\n  {\n    onSuccess: () =\u003e console.log('Added to cart'),\n    onError: (error) =\u003e console.error('Failed to add:', error),\n  }\n)\n```\n\nIf `onError` is not provided, chain errors are still logged to the browser console via `console.error`.\n\n## Notes\n\n- Callbacks use callback-style (not Promise) to avoid issues with React's Suspense boundary during action dispatch.\n- Action identifiers must use `snake_case` from v21. Dash-case identifiers still work but are deprecated.\n\n## Related\n\n- [POS actions reference](pos-actions-reference) — list of available action identifiers\n- [checkout:start](pos-checkout-start-action) — start checkout programmatically\n- [sync:full](pos-sync-full-action) — force a full POS data sync"}