How to Create a Virtual Field in the Pricing Sublist on Customer Records

Adding custom functionality to standard NetSuite forms can enhance user experience and streamline data management. One way to do this is by adding a virtual field to the pricing sublist on customer records. The following guide explains how to create a user event script to add a virtual field named Custom Pricing to the Item Pricing sublist.

Overview of the Code

The provided SuiteScript 2.0 user event script creates a custom field in the pricing sublist of a customer record. This field is sourced from the Price Level list and is added when the record is in edit mode.

Step-by-Step Explanation

  1. Dependencies: The script requires three modules: N/record, N/log, and N/ui/serverWidget.
  2. Function Setup:
  • The beforeLoad function is triggered before the form loads. This ensures the custom field is available when the record is opened for editing.
  1. Context and Form Access:
  • The script retrieves the form from the context object.
  • The Item Pricing sublist is identified using its ID, itempricing.
  1. Adding the Custom Field:
  • The script uses addField() to create a new field (custpage_custom_pricing) with the type SELECT.
  • The field’s source is set to pricelevel, linking it to NetSuite’s existing price level list.
  • The field’s display type is set to ENTRY, making it editable in the form.
  1. Error Handling:
  • A try-catch block captures and logs any errors that occur during the script execution.

Full Code for Adding the Virtual Field

define(['N/record', 'N/log', 'N/ui/serverWidget'], (record, log, serverWidget) => {
    function beforeLoad(context) {
        try {
            // Retrieve the form from the context object
            var form = context.form;


            // Locate the Item Pricing sublist by its ID
            var itemPricingSublist = form.getSublist({
                id: 'itempricing'
            });


            log.debug('itemPricingSublist', itemPricingSublist);


            if (itemPricingSublist) {
                // Add a custom virtual field to the sublist
                itemPricingSublist.addField({
                    id: 'custpage_custom_pricing',
                    type: serverWidget.FieldType.SELECT,
                    label: 'Custom Pricing',
                    source: 'pricelevel'
                }).updateDisplayType({
                    displayType: serverWidget.FieldDisplayType.ENTRY
                });
            }
        } catch (error) {
            // Log errors for debugging
            log.error({
                title: 'Error in beforeLoad user event script',
                details: error.message
            });
        }
    }


    return {
        beforeLoad: beforeLoad
    };
});

Result and Use Case

When this script is deployed to customer records in NetSuite, it adds a virtual Custom Pricing field to the Item Pricing sublist. Users can interact with this field to select different pricing levels directly within the sublist. This approach is useful for adding quick reference fields or input options that enhance data management workflows.

Leave a comment

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