Skip to content

Script debugger

Use evaluate_script to execute JavaScript on a sandbox instance via the script debugger API.

Quick start

Prompt:

What is the current site ID on my sandbox?

Example script:

javascript
dw.system.Site.current.ID

Requirements

  • Valid dw.json credentials
  • Script debugger enabled in Business Manager
  • SFRA or SiteGenesis storefront in the cartridge path, or a custom breakpointFile
Username is case-sensitive The debug API requires the username to match Business Manager casing exactly.
Sandbox only Only use the script debugger on sandbox or development instances.

Parameters

ParameterRequiredDefaultDescription
scriptYes-JavaScript expression to evaluate
siteIdNoRefArchSite ID for the request
localeNodefaultLocale segment (fallback if locale-less fails)
timeoutNo30000Execution timeout in ms
breakpointFileNoAutoCustom controller file for breakpoint
breakpointLineNoAutoSpecific breakpoint line

Script rules

  • Do not use return at the top level. Use expressions.
  • Do not use require(); use the global dw.* namespace.
  • Wrap multi-step logic in an IIFE.
  • Use JSON.stringify() for objects or arrays.

Example IIFE:

javascript
(function() {
  var p = dw.catalog.ProductMgr.getProduct('25518704M');
  if (!p) return 'Not found';
  return JSON.stringify({ id: p.ID, name: p.name, online: p.onlineFlag });
})()

Common use cases

Site information

javascript
dw.system.Site.current.ID

Product lookup

javascript
(function() {
  var p = dw.catalog.ProductMgr.getProduct('25518704M');
  if (!p) return 'Not found';
  return JSON.stringify({ id: p.ID, name: p.name, online: p.onlineFlag });
})()

Site preferences

javascript
JSON.stringify(Object.keys(dw.system.Site.current.preferences.custom))

Troubleshooting

ErrorCauseFix
invalid returnTop-level returnUse expression or IIFE
Cannot call method of nullUsing require()Use dw.* globals
Timeout waiting for breakpointWrong siteId or debugger disabledVerify siteId and enable debugger
NotAuthorizedExceptionMissing permissionsEnable Script Debugger permission
No compatible storefront cartridgeMissing SFRA/SiteGenesisDeploy storefront or set breakpointFile

Best practices

  • Keep scripts short and synchronous
  • Use IIFEs for multi-step logic
  • Always null-check objects
  • Use JSON.stringify() for readable output

Released under the MIT License.