๐ง Business Use Case
Sometimes, you want to extend the functionality of a NetSuite record form by adding:
- A custom tab
- A button or link to trigger a Suitelet process
- An embedded list of related data
This pattern is especially useful when you want to:
- Launch external processes like e-signatures, approvals, or workflows
- Display related records (e.g., signature logs, audit trail, custom objects)
- Maintain a cleaner, tab-based user interface for specific roles
๐ก What This Script Does
- Adds a custom tab called โSample Tabโ to a record when viewed or edited
- Injects an HTML link to a Suitelet that passes the record ID
- Adds a sublist to the tab to show related โSignature Requestsโ (example use case)
โ Key Features
| Feature | Purpose |
|---|---|
addTab() | Creates a new custom tab in the UI |
addField({type: 'inlinehtml'}) | Injects dynamic HTML content like links |
url.resolveScript() | Builds the Suitelet URL with script/deployment ID |
addSublist() | Adds a table to the tab (static or dynamic content) |
๐ป Script: Add a Suitelet Link in a Tab Using User Event
/**
* @NApiVersion 2.x
* @NScriptType UserEventScript
*/
define(['N/record', 'N/runtime', 'N/ui/serverWidget', 'N/url'],
function(record, runtime, serverWidget, url) {
function beforeLoad(scriptContext) {
var currentUserID = runtime.getCurrentUser().id;
// Only apply on Edit or View from UI
if ((runtime.executionContext === runtime.ContextType.USER_INTERFACE) &&
(scriptContext.type === scriptContext.UserEventType.EDIT ||
scriptContext.type === scriptContext.UserEventType.VIEW)) {
// 1. Add a new Tab
var customTab = scriptContext.form.addTab({
id: 'custpage_sample_tab',
label: 'Sample Tab'
});
// 2. Add a clickable HTML link to Suitelet on the tab
var linkField = scriptContext.form.addField({
id: 'custpage_new_req_link',
type: serverWidget.FieldType.INLINEHTML,
label: ' ',
container: 'custpage_sample_tab'
});
// 3. Build the URL for the Suitelet dynamically
var linkURL = url.resolveScript({
scriptId: 'customscriptsuiteletsample_yourfirstsamp', // Replace with your actual script ID
deploymentId: 'customdeploysuiteletsample_yourfirstsamp'
}) + '&recordid=' + scriptContext.newRecord.id;
linkField.defaultValue = '<b>Click <a href="' + linkURL +
'">here</a> to create a new document signature request record.</b>';
// 4. Optional: Add a custom sublist to the same tab
var sigSublist = scriptContext.form.addSublist({
id: 'custpage_sig_req_sublist',
type: serverWidget.SublistType.LIST,
label: 'Document Signature Requests',
tab: 'custpage_sample_tab'
});
sigSublist.addField({ id: 'custpage_req_name', type: serverWidget.FieldType.TEXT, label: 'Name' });
sigSublist.addField({ id: 'custpage_req_status', type: serverWidget.FieldType.TEXT, label: 'Status' });
sigSublist.addField({ id: 'custpage_req_created', type: serverWidget.FieldType.DATE, label: 'Date Created' });
// NOTE: You can populate the sublist dynamically via Suitelet or Client Script
}
}
return {
beforeLoad: beforeLoad,
};
});
๐ Implementation Tips
- Make sure the User Event is deployed on the record type (e.g., Customer, Estimate, Sales Order)
- Replace
scriptIdanddeploymentIdinresolveScript()with your own Suitelet values - Sublist content can be populated in a more advanced version using related record search results
๐งช Real-World Use Cases
| Use Case | Example |
|---|---|
| โ Document Signing Integration | Launch Docusign Suitelet from a custom tab |
| ๐ Approval Workflows | Trigger a Suitelet that routes a document to managers |
| ๐ Data Sync/Sync Log | Display synced records and provide re-sync button |
| ๐ Related Records | Show a table of related transactions or files |
Leave a Reply