Key Suitelet Functions for Custom UI Development

Suitelets provide a powerful way to create custom user interfaces (UI) and extend NetSuite’s standard functionality. Below are some of the most commonly used Suitelet functions and their implementations.

Functions Covered

1. serverWidget.createForm(options) – Creating a Form

Purpose:

Creates a custom UI form within a Suitelet.

Usage:

define([‘N/ui/serverWidget’], function(serverWidget) {

function onRequest(context) {

var form = serverWidget.createForm({

title: ‘Customer Feedback’

});

context.response.writePage(form);

}

});

Best Practices:

Keep form titles and labels user-friendly.

Use meaningful IDs for fields.

2. response.writePage(form) – Rendering Pages

Purpose:

Displays the Suitelet form in the NetSuite UI.

Usage:

function onRequest(context) {

var form = serverWidget.createForm({ title: ‘Order Summary’ });

context.response.writePage(form);

}

Common Issues:

If omitted, the Suitelet will not render the form properly.

If using response.write(), ensure proper HTML structure.

3. request.getParameter(name) – Handling User Inputs

Purpose:

Retrieves form data submitted by users.

Usage:

function onRequest(context) {

if (context.request.method === ‘POST’) {

var userInput = context.request.parameters.custpage_input;

log.debug(‘User Input:’, userInput);

}

}

Best Practices:

Always sanitize user inputs to prevent security vulnerabilities.

4. record.load(options) – Fetching Records in Suitelets

Purpose:

Retrieves an existing NetSuite record within a Suitelet.

Usage:

define([‘N/record’], function(record) {

function loadCustomer() {

var customer = record.load({

type: record.Type.CUSTOMER,

id: 123

});

log.debug(‘Customer Name:’, customer.getValue({ fieldId: ‘companyname’ }));

}

});

Common Issues:

Permissions Error: Ensure the user has access to the record.

Incorrect Record Type: Use record.Type.<TYPE> to avoid typos.

Leave a comment

Your email address will not be published. Required fields are marked *