SuiteScript 2.0 – @NAmdConfig – dynamic entries

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.

Code page 1

In the code below, I’m dynamically importing a second non-AMD library that renders a second component, a catalog browser control.

Code page 2

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.

Config file explained

I hope this saves you the hours of research that went into these few lines of my code!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s