π§© Business Scenario
Youβre building a Suitelet with an editable list of values β such as expense items, time entries, or project costs β and you’d like to automatically show a running total of the values entered into a currency field (like βAmountβ).
NetSuite doesnβt calculate or display sublist totals by default in Suitelets. But using the updateTotallingFieldId() method, you can enable inline sublist totals, just like in standard NetSuite transaction records.
π§ Objective
Create a Suitelet with:
- A sublist in INLINEEDITOR mode
- A custom currency field (
amount) that automatically totals values - Multiple rows pre-populated with values
- A running total visible at the bottom of the sublist
π» Script: Suitelet with Running Total on Sublist
/**
* @NApiVersion 2.x
* @NScriptType Suitelet
*/
define(['N/ui/serverWidget', 'N/record'], function(serverWidget, record) {
return {
onRequest: function(params) {
var form = serverWidget.createForm({ title: 'Simple Form with Totals' });
// Create the Sublist with Totals
var sublist = form.addSublist({
id: 'mylist',
type: serverWidget.SublistType.INLINEEDITOR,
label: 'Transaction Lines'
});
sublist.addField({
id: 'description',
type: serverWidget.FieldType.TEXT,
label: 'Description'
});
sublist.addField({
id: 'amount',
type: serverWidget.FieldType.CURRENCY,
label: 'Amount'
});
// Enable Totalling
sublist.updateTotallingFieldId({
id: 'amount'
});
// Prepopulate Sublist Rows
sublist.setSublistValue({ id: 'description', line: 0, value: 'Design Fee' });
sublist.setSublistValue({ id: 'amount', line: 0, value: '250.00' });
sublist.setSublistValue({ id: 'description', line: 1, value: 'Consulting' });
sublist.setSublistValue({ id: 'amount', line: 1, value: '500.00' });
// Add a second dummy sublist to show multiple sections
form.addSublist({
id: 'dummy',
type: serverWidget.SublistType.STATICLIST,
label: 'Static Info'
});
// Render the Page
params.response.writePage(form);
}
};
});
π Key Function: updateTotallingFieldId()
This special method enables automatic summation of a currency field at the bottom of the sublist. It does not calculate row-by-row running totals, but gives you a subtotal footer, similar to native transactions in NetSuite.
π§ Important: This only works with INLINEEDITOR sublists and supported field types like
CURRENCY,INTEGER, orFLOAT.
πΈ Visual Output (Simulated)
| Description | Amount |
|---|---|
| Design Fee | $250.00 |
| Consulting | $500.00 |
| Total | $750.00 β (auto-calculated) |
π Limitations
- Only works with supported field types (currency, integer, float)
- Total appears only at the bottom, not per-row
- Requires INLINEEDITOR sublist type
- Does not support dynamic total changes via client script β it’s calculated at render time
π§ͺ Real Use Cases
| Use Case | Benefit |
|---|---|
| Expense Form Suitelet | Totals user-entered expenses |
| Commission Payout Sheet | Show total commissions |
| Project Line Item Estimator | Dynamic total on client pricing sheet |
| Time Tracking Summary | Total billable hours in editable list |
π‘ Pro Tips
- You can combine this with a Client Script to display live totals (e.g., updating a header field or status message).
- For transaction-like behavior, pair this sublist with a Save button and server-side logic to process the entries.
π Summary
By using updateTotallingFieldId() in a Suitelet sublist, you can offer immediate visual feedback to users β showing calculated totals right inside a custom form. This creates a more intuitive user experience for financial inputs, time entry logs, and internal tools.
Leave a Reply