Use a Custom Module Client Script

The following sample is a user event script deployed on a non-inventory item record. Before the record loads, the script updates the form used by the record to add new text fields, a sublist, and buttons that call the methods in a custom module client script (clientDemo.js). The buttons access the current record and set values for some of the form’s fields. This sample demonstrates how to customize a form, use a custom module client script, and see the new fields and buttons in action.

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.

Important:

This sample uses SuiteScript 2.1. For more information, see SuiteScript 2.1.

          /**
 * @NApiVersion 2.1
 * @NScriptType UserEventScript
 * @NModuleScope SameAccount
 */
define([], () => {
    return {
        beforeLoad: params => {
            // Get a reference to the current form that is about to load
            let form = params.form;
 
            // Add several custom fields to the form
            let textfield = form.addField({
                id: 'custpage_textfield',
                type: 'text',
                label: 'Text'
            });
            let resultfield = form.addField({
                id: 'custpage_resultfield',
                type:'text',
                label: 'Result'
            });
            let sublistResultfield = form.addField({
                id: 'custpage_sublist_resultfield',
                type: 'text',
                label: 'Sublist Result Field'
            });
 
            // Get a reference to the sitecategory sublist
            let sublistObj = form.getSublist({
                id: 'sitecategory'
            });
             
            // Add a custom field to the sublist
            let subtextfield = sublistObj.addField({
                id: 'custpage_subtextfield',
                type: 'text',
                label: 'Sublist Text Field'
            });
 
            // Set the module path to the previous sample script
            form.clientScriptModulePath = './clientDemo.js';
             
            // Add two custom buttons to the form
            form.addButton({
                id: 'custpage_custombutton',
                label: 'SET_GET_VALUE',
                functionName: 'test_set_getValue'
            });
            form.addButton({
                id: 'custpage_custombutton2',
                label: 'SET_GETCURRENTSUBLISTVALUE',
                functionName: 'test_set_getCurrentSublistValue'
            });
        }
    };
}); 

        

General Notices