Skip to main content

NetSuite - Force Single Select on Multi-Select Field

Issue: We had a request from our Stakeholders to change a Multi-Select Field to a Single Select.  The Issue came up with this field being part of a bundle that we use.  

We didn't want to deal with this being reverted or causing issues after we updated the bundle in the future, so I cam up with this work around.

It is a Client Script that will throw an error to the user if they select more than one, and then it will reduce the selection to one option.

/**
 * @NApiVersion 2.x
 * @NScriptType ClientScript
 *
 * 2025 Prevents multiple selections in a multi-select field * by showing an error message and removing the last selected value.
 *
 */
define(['N/ui/message', 'N/runtime'], function(message, runtime) {
    function fieldChanged(context) {
        var scriptObj = runtime.getCurrentScript();
        var fieldName = scriptObj.getParameter({             name: 'custscript_CUSTOM_FIELD'             });  // Field ID to prevent multiple selections
       
        var currentRecord = context.currentRecord;
        var fieldId = context.fieldId;

        if (fieldId === fieldName) {
            var selectedValues = currentRecord.getValue({ fieldId: fieldName });
            if (selectedValues.length > 1) {
                // Show error message if more than one option is selected
                message.create({
                    title: 'Error',
                    message: 'You can only select one option.',
                    type: message.Type.ERROR
                }).show();

                // Remove the last selected value
                selectedValues.pop();
                currentRecord.setValue({
                    fieldId: fieldName,
                    value: selectedValues
                });
            }
        }
    }

    return {
        fieldChanged: fieldChanged
    };
});

Comments

Popular posts from this blog

Logo Design

I started working on some Freelancer.com Contests.  It's been good to push me to create some work within a somewhat restricted space.  Also helping me keep the creative juices flowing.  This is a design I did for Philippe Diamonds.  It was rejected.  I like it though, so I thought I would share. I have worked on a bunch of others, either they aren't done yet, or I don't fully endorse the design.

Delta Cubes - The Dark Side of The Greendale

I'm a huge fan of Community ( @nbccommunity )  And I am also a huge fan of Pink Floyd.  So I decided to do a little mash-up after watching the last episode Season 04 Episode 07 - "Economics of Marine Biology"  And since I haven't posted in awhile, I thought I would Share.

Mitt Romney Poster

Romney 2012 Believe in America Trying to again stay productive, and get more work out there and into my portfolio.  Did a quick Poster of Mitt Romney. I am not necessarily Endorsing him, but  wanted to do someone who was relevant to the times.