Add a Field that Displays Running Total to a Sublist

PHOTO EMBED

Sun Jun 05 2022 09:55:39 GMT+0000 (Coordinated Universal Time)

Saved by @Lefemmenikita

Add a Field that Displays Running Total to a Sublist
Published 08/21/2020 12:46 AM   |    Updated 11/05/2021 02:13 AM   |    Answer Id: 94603
SuiteCloud Platform SuiteScript SuiteScript 2.x SuiteScript 2.x Script Types SuiteScript 2.x Suitelet Script Type SuiteScript 2.x Suitelet Script Type Code Samples Custom Forms Add a Field that Displays Running Total to a Sublist

The following sample shows how to add a field to the sublist that calculates and displays a running total for it.

Note This script sample uses the define function, which is required for an entry point script (a script you attach to a script record and deploy). You must use the require function if you want to copy the script into the SuiteScript Debugger and test it. For more information, see SuiteScript 2.x Global Objects.
/**
 * @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'
            });
            var sublistObj2 = form.addSublist({
                id: 'mylist',
                type: serverWidget.SublistType.INLINEEDITOR,
                label: 'List'
            });
            sublistObj2.addField({
                id: 'description',
                type: serverWidget.FieldType.TEXT,
                label: 'Description'
            });
            sublistObj2.addField({
                id: 'amount',
                type: serverWidget.FieldType.CURRENCY,
                label: 'Amount'
            });
            sublistObj2.updateTotallingFieldId({
                id: 'amount'
            });
            sublistObj2.setSublistValue({
                id: 'description',
                line: 0,
                value: 'foo'
            });
            sublistObj2.setSublistValue({
                id: 'amount',
                line: 0,
                value: '10'
            });
            sublistObj2.setSublistValue({
                id: 'description',
                line: 1,
                value: 'bar'
            });
            sublistObj2.setSublistValue({
                id: 'amount',
                line: 1,
                value: '15'
            });
            form.addSublist({
                id: 'dummy',
                type: serverWidget.SublistType.STATICLIST,
                label: 'Dummy'
            });
            params.response.writePage(form);
        }
    };
});
content_copyCOPY

https://netsuite.custhelp.com/app/answers/detail/a_id/94603/kw/total sublist