Per my most recent blog posts, you’ve probably noticed I’m focusing on reusable components in the NetSuite stack. One of the first problems I hit was dynamically adding multiple non-AMD libraries to a Suitelet.
For you savvy NetSuite developers, please don’t immediately tell me I’m doing this the hard way. I know I can create an @NAmdConfig JSON that exports multiple libraries. However, that would require a unique @NAmdConfig for practically every page that included multiple components. Ugly!
And yes, I realize I could put all my code for all my controls in one large library. But I’m the guy who wipes down the sink in public restrooms when I’m done. I want this to be a well-organized codebase. That’s just me.
To that end, here’s how you’d accomplish dynamically loading non-AMD libraries in a SuiteScript 2.0 Suitelet. These next 2 images show code from one Suitelet. In the first image, I’m showing the standard method of importing a non-AMD library. It represents a search control that I’m placing in the page.
In the code below, I’m dynamically importing a second non-AMD library that renders a second component, a catalog browser control.
Here, I’m dissecting the config object. I found this a little confusing at first. Hopefully, this reference helps. It works the same in the *@NAmdConfig ./LogicCompSearchLib.json file and associated library.
I hope this saves you the hours of research that went into these few lines of my code!