Hi, does anyone have an example script that can st...
# suitescript
b
Hi, does anyone have an example script that can stop the entering of items in NetSuite if naming convention is not correctly followed? For example we have some users who add a "period" to the end of a description, i.e. Mallet. instead of just entering Mallet We want to be able prevent users adding the period.
m
You can use a workflow for this! REGEX validation is probably easier in SuiteScript, but SuiteFlow can handle this sort of stuff too, and it's more admin-friendly to manage. Use a before record submit event type to cover csv imports and inline edit scenarios as well. Lots of options here.
j
I recommend use a CS on fieldChanged and saveRecord with a pop up not only warning but also cleaning the name. It is also recommended to apply the same logic to a workflow to handle the backend operations, like csv updates. Lastly, for manteinance reasons it will be better put the cleaning function in a custom module.
Copy code
const cleanName = (value) => {
        if (!value) return value;

        return value
            // invisibles (incluye non-breaking space)
            .replace(/[\u0000-\u001F\u007F\u00A0]/g, ' ')
            // colapse multiple spaces
            .replace(/\s{2,}/g, ' ')
            // delete end punctuation and spaces 
            .replace(/[\s.,;:!?\-]+$/g, '')
            // delete leading spaces
            .replace(/^\s+/g, '');
    };