Week 7 • Module 12

N/url & N/redirect

Generating URLs and navigating users programmatically

🔗 N/url Module

The url module generates URLs for records, scripts, and NetSuite domains.

url.resolveRecord()

const url = require('N/url');

// Generate URL to view a Sales Order
const recordUrl = url.resolveRecord({
    recordType: 'salesorder',
    recordId: 12345,
    isEditMode: false
});
// Returns: /app/accounting/transactions/salesord.nl?id=12345

url.resolveScript()

// Generate URL to a Suitelet
const suiteletUrl = url.resolveScript({
    scriptId: 'customscript_my_suitelet',
    deploymentId: 'customdeploy_my_suitelet',
    params: {
        action: 'view',
        customerId: 123
    }
});
// Returns: /app/site/hosting/scriptlet.nl?script=123&deploy=1&action=view&customerId=123

url.resolveDomain()

// Get account-specific domain
const domain = url.resolveDomain({
    hostType: url.HostType.APPLICATION
});
// Returns: https://12345.app.netsuite.com

↪️ N/redirect Module

The redirect module navigates users from server-side scripts (User Event afterSubmit, Suitelet).

redirect.toRecord()

const redirect = require('N/redirect');

// In afterSubmit or Suitelet POST handler
redirect.toRecord({
    type: 'salesorder',
    id: newRecordId,
    isEditMode: false
});

redirect.toSuitelet()

redirect.toSuitelet({
    scriptId: 'customscript_confirmation',
    deploymentId: 'customdeploy_confirmation',
    parameters: {
        status: 'success',
        recordId: 12345
    }
});

✅ Server-Side Only

N/redirect only works in server-side scripts. For client-side navigation, use window.location or the N/url module to generate URLs.

📖 Finding This in the Docs

To look up URL generation and redirects:

  1. Go to docs.oracle.com → SuiteScript 2.x Modules
  2. Click on N/url Module for URL generation
  3. Click on N/redirect Module for server-side navigation

Key pages to bookmark:

🎯 Key Takeaways