Casebook06 · SuiteScript
One helper, pasted into about 210 files
Small helpers like isEmpty are copied into every script. Over the years the copies drift apart, and a bug fixed in one file lives on in the others.
- Casebook 06
- SuiteScript
What you notice
A bug is fixed in one script, and a month later the same bug appears in another. Two scripts that “do the same check” give different answers.
Why it happens
In 1.0, sharing code meant adding library files to each script record, so many developers pasted helpers into the script instead. In an automatic pattern search of our archive, about 210 files across 27 clients define their own isEmpty helper (approximate), often in slightly different versions.
The fix in 2.1
Put shared helpers in one module and load it with define. Fix a bug once and every script gets it.
// lib_utils.js
define([], () => ({
isEmpty: (v) => v === null || v === undefined || v === '' || (Array.isArray(v) && v.length === 0),
}));
// any script
define(['./lib_utils'], (utils) => { /* utils.isEmpty(value) */ });
What to check in your account
Search the File Cabinet for helper names such as isEmpty, isNull or getAllResults and count the copies. That number is a good measure of how much a shared library will save.