sn-sdk-setup
ServiceNow SDK Setup
The ServiceNow SDK (now-sdk) CLI scaffolds, builds, and deploys Fluent DSL applications. Use this skill for any SDK installation, project creation, authentication, or environment validation task.
Reference Files
Read only the file relevant to your task. Do not pre-load references at session start.
| File | When to read |
|---|---|
references/setup-workflows.md |
When scaffolding a new project, configuring auth, converting an existing app, or diagnosing environment issues |
references/auth-profiles.md |
When configuring Basic or OAuth auth, managing named aliases, or passing --auth to commands |
references/init-templates.md |
When choosing a project template or passing non-interactive init flags |
references/convert-existing-app.md |
When converting an existing application from XML metadata or Update Set |
references/third-party-libraries.md |
When adding npm packages to an SDK project |
references/js-modules-types.md |
When using JS modules in src/server/, TypeScript in server-side modules, or @servicenow/glide type definitions |
references/cli-reference.md |
When looking up auth, init, build, install, download, or dependencies command flags |
Scripts
| Script | When to use |
|---|---|
scripts/check-environment.sh |
When validating the developer environment before starting SDK work. Use --offline in CI pipelines. |
Hard Rules
- Read before advising. Always read
references/setup-workflows.mdbefore giving setup instructions. Do not rely on memory for command syntax — SDK commands change between versions. - Use
now-sdk auth --add, notauth saveorlogin.auth savedoes not exist.loginis deprecated. The correct command isnow-sdk auth --add <url> --alias <name>. - Always use a named alias. Use
now-sdk auth --add <url> --alias dev— aliases allow multiple instances. - Never pick a template without understanding the use case. Follow the discovery flow in the scaffold behavior below. Default to
typescript.basiconly as a last resort after two unanswered prompts. - The scope prefix comes from now.config.json. When helping with Fluent DSL code after setup, tell the user to activate the sn-sdk-fluent skill.
- Never run install without a successful build first.
now-sdk installdeploys whatever is indist/. Running it without a priornow-sdk buildsilently pushes stale or missing artifacts. Build must complete cleanly before deploy. - Always verify auth before deploying. OAuth tokens expire silently. Run
now-sdk auth --listand confirm the correct alias is active before every deploy. A mid-deploy auth failure is confusing and hard to diagnose. sys_app.dois the app record, not the running UI. After deploy, the link in the install output points to the app record. The live UI URL is theendpointvalue defined in theUiPage()call in the.now.tssource — e.g.https://<instance>.service-now.com/<endpoint>.do.
Behavior by Task Type
New project scaffold
Read references/setup-workflows.md and references/init-templates.md first, then follow this flow:
Step 1 — Instance URL If not already provided, ask:
"What's your ServiceNow instance URL? (e.g. https://dev12345.service-now.com)"
Step 2 — Auth
- Recommend OAuth. Ask: "OAuth (recommended) or Basic auth?"
- Important: OAuth requires interactive terminal input — Claude Code cannot handle this. See
references/cli-reference.md→ auth --add (token refresh) for the Terminal workaround. - Once they confirm auth succeeded, verify with:
now-sdk auth --list
Step 3 — What to build Ask one question with examples to guide the answer:
"What are you building? For example:
- Business rules, script includes, flows, Service Portal widgets →
typescript.basic- App with a custom React UI page →
typescript.react- App with a custom Vue UI page →
typescript.vue"
- If they answer → map to the right template, state your reasoning in one sentence, confirm with user, then scaffold.
- If no answer → ask once more: "Does it need a custom UI, or is it server-side only?"
- If still no answer → use
typescript.basicand say: "Going withtypescript.basic— works for everything server-side. You can add React later withpartial.typescript.react."
Step 4 — Scaffold
now-sdk init \
--template <chosen-template> \
--appName "<App Name>" \
--packageName <package-name> \
--scopeName <x_scope_name> \
--auth dev
Then: npm install
Step 5 — Hand off
"Project ready. Activate the sn-sdk-fluent skill to start writing .now.ts files."
Authentication setup (standalone)
- Read
references/setup-workflows.mdsection 2 (Configure Authentication) - Determine Basic vs OAuth — recommend OAuth
- For full flag reference and alias management, read
references/auth-profiles.md. - OAuth requires interactive terminal input — Claude Code cannot handle this. See
references/cli-reference.md→ auth --add (token refresh) for the Terminal workaround. - Verify with:
now-sdk auth --list
Convert existing application
- Read
references/setup-workflows.mdsection 3 (Convert Existing Application) - For full 5-step workflow with gotchas, read
references/convert-existing-app.md. - Walk through the full workflow:
init --from→transform→build→install
Build & Deploy
Pre-deploy checklist — always run through this first:
now-sdk auth --list→ confirm the correct alias is marked as default- Ensure source changes are saved and complete
- Run build — it must succeed cleanly before proceeding
The sequence — never skip or reorder:
npm run build # now-sdk build — type-check + bundle
npm run deploy # now-sdk install — push artifacts to instance
Post-deploy verification — always confirm the right version landed:
- Open
https://<instance>.service-now.com/sys_app.do?sys_id=<scopeId>(scopeId is innow.config.json) - Confirm version matches what you just deployed
- Confirm state is
Active - If either is wrong, check
sys_app_install_logon the instance for errors
Finding the live UI URL after deploy:
The install output shows a sys_app.do link — that is the app record, not the running UI. To get the live URL:
- Open the
UiPage()definition in your.now.tssource file - Read the
endpointvalue (e.g.x_snc_myapp_portal.do) - Live URL:
https://<instance>.service-now.com/<endpoint>.do
Targeting a specific instance:
now-sdk install --auth <alias> # override the default alias
Common failures and fixes:
| Symptom | Cause | Fix |
|---|---|---|
| Auth error mid-deploy | Expired OAuth token | OAuth token refresh requires interactive input — see references/cli-reference.md → auth --add (token refresh) for the Terminal workaround, then retry deploy. |
| "Could not determine app installation status" | Upload processor returns no tracker ID; SDK's sys_upgrade_history poll times out after 30s |
Use --reinstall: now-sdk install --auth <alias> --reinstall. This uninstalls first, then reinstalls cleanly via the tracker path. |
| Install succeeds but UI shows old code | Build was skipped or stale | Re-run npm run build then npm run deploy |
| Type-check error blocks build | TypeScript error in source | Fix the error reported — do not bypass |
| Scope conflict on install | Another app owns the scope | Check sys_app for conflicting scope, resolve before retrying |
Environment validation
- Direct user to run
scripts/check-environment.sh --offline(if in CI) or without flag (to also check connectivity) - Interpret the JSON output and explain any failed checks