What's your preferred way of storing global settin...
# suitescript
b
What's your preferred way of storing global settings for a NetSuite account? Here are different methods I've used in the past. • Use a form Suitelet as a settings page, and store the data in a JSON file in the File Cabinet. (I like this one the best, but I'd rather use a standard NetSuite page.) • Use a custom record type. (I don't really like this method since you could have multiple instances of the custom record type.) • Use script parameters, and set the "Preference" to "Company". (I don't like this because then the values are tied to only one script.)
s
Custom record type
n
Custom record type. Control access, block delete and creation via script if that's a concern.
s
storing settings in a file in the file cabinet makes the settings inaccesible for client scripts
👍 2
b
I would just write a Suitelet to get the settings from the File Cabinet
You can't access the custom record data without server API calls either. Not really much difference. Also, you can control who has access to a Suitelet.
n
But you can't block deletion or editing of the file external to the intended process, no? These are extreme edge cases, but it seems like extra steps to get to the same place.
s
the custom record approach has the benefit of a GUI for free
s
You can't access the custom record data without server API calls either. Not really much difference.
What? record is certainly available on the client side. For your sescond point, you can control who has access to a custom record as well.
b
@stalbert True, but I don't really mind creating my own form with
serverWidget.createForm()
.
s
createForm()
is one the weakest APIs in all of SuiteScript.
1
but that's an entirely different discussion
b
@Sandii Yes, there are functions available for searching and loading records via client, but those still do server requests behind the scenes.
n
But file.load for the JSON is a server request
s
IMHO there's better places to spend time than creating configuration suitelets to provide a UI for a record
b
@Nicholas Klug I never said it wasn't
s
Right, but why would I want to build a suitelet to do the middle step when there is already an API (using record or search) that already does it? It's the same idea as the form. I feel like it's akin to not wanting to use lodash and instead writing your own functions that do the same thing. Why reinvent the wheel?
💯 1
s
Using a custom record, you save the values as individual fields (not a JSON blob) then load the record as needed (and with NFT that record is a natural JS object already)
n
This seems like a lot of work to make a square wheel.
😅 1
s
creating a suitelet from scratch generally results in a square wheel
it will roll, but it isn't fun.
s
It's not that its harder/easier, it's just unnecessary work and more code to maintain.
n
You have to custom roll a form, middle suitelet to facilitate, lose all hierarchy, and gain no permission control? Or you can create a custom record, write a script that blocks all updates, creates, or deletes if the role != administrator
and call it a day
and it's a whopping 8 usage cheaper 😉
b
Yeah. My original intent was not to fight for using the file cabinet. Thanks for the feedback. I was hoping there was a way to create custom fields somewhere global like the Company Information page.
I've only used the file cabinet approach once for displaying a Suitelet in different ways because the client wanted a way to edit preferences from the UI. I loaded the Suitelet in a native modal window and stored the values of the 2 fields in JSON.
m
wait wait, so in what case is it ok to create parameters for a script and set it as a company wide field? I've been doing it like that since I started learning suitescript 5 months ago
n
IMO, company wide parameters aren't bad but the problem is being real clear on where they live
that is to say, what script holds the original parameter? Does the processing payment type exist on the Payment Process Map/Reduce? Payment Delivery Map/Reduce? etc. etc.
m
I always set them as company wide and I'll have them appear in the company settings page at the bottom of the "Custom preferences" subtab, but I'm still learning
n
I've seen people name script parameters "525_thingIDo" where 525 is the script internal ID
200iq 1
but that can easily be broken cross environment
b
@Mr_Tib Yeah, I like that approach. You can use
config.load()
to get the field values from any server script.
n
personally, this is why I use a custom record approach. You have one hub that you can quickly config when migrating across several environments
and you have the benefit of leveraging NetSuite's record system
You can also hand the documentation to an admin for an environment, and say "Payment Type for the config record should be Bank of America ACH"
and they know precisely what it should be. Whereas if it is an internal ID in a JSON, that's harder.
m
@Nicholas Klug Your approach sounds interesting, I've never tried that. Is it considered a bad practice or trying to reinvent the wheel?
n
It's been standard practice at both of the consulting firms I've worked at, but your mileage may vary.
m
Got it. I'm only asking because I'm still getting the hang of everything so it's nice to know both approaches
n
No problem. Again, company preferences aren't bad, you just need to document in the event that you may need to delete a script later. Documentation is good, Documentation is life :)
m
Yeah I agree. I've also been having a hard time not hardcoding stuff sometimes, would you say is 100% possible to not hardcode stuff?
n
There's very rarely a reason to hardcode something
m
Yeah, I figured as much. Probably just bad architecture on my part.
n
Most likely. There are times you can kind of justify it though. Like system generated roles, payment options, things that should be immutable
If you ever hardcode things, absolutely comment what that hardcoded value is. If you put payment type : 1, you absolutely have to comment what "1" denotes.
m
I'm hardcoding the IDs of all 5 expense categories that are available in the environment I'm working in
n
Step 1 - make sure every single one of those hardcodings has // This is Meals/Entertainment etc. next to them. Step 2 - You probably should go back and make these a non-hardcoded value, but if they never change and you're a junior, I doubt anyone will hate you for it as long as it's commented
m
Yeah I did comment what the ID corresponds to. However I'm working on Sandbox so, for the final deployment to prod, I'm going to have to go and create those expense categories and update the Ids on my code
n
Ah. Stop right there. It's time to make everything either a script parameter or a custom record 🙂
s
Yeah that right there is the exact reason to not hard code lol
n
if you have a "production" code version and a "sandbox" code version, you're asking for trouble. Now, I've seen big 4 consultants do lazy things like detect if they're in the sandbox and do X, if in prod do Y. But you can be better than them and do it the right way
m
Yeah, that's how I figured I was not taking the best approach, sounds like you said, asking for trouble
At the company I work for we usually have too much work, more than we should so we just wing it sometimes and not stop to actually plan everything as we should
n
Untitled
b
im in the custom record group
if you want to have different configurations for different sandboxes, you will like having multiple configuration records
n
config record example
b
@Nicholas Klug That would fail if someone deletes the first configuration record for some reason. I prefer to get it via a search and take the first result.
n
It would. Unless you have a script in place that blocks creation and deletion of the custom record.
👍 2
at my last consultancy, I had a coworker go so far as to block all access to a custom record from the UI and only access it through a suitelet through a custom tab. It was a really in depth solution, but it was intended to deploy to clients' system so we could quickly set up SFTP configurations
s
In practice, people (end users) don't care about or delete your custom config record #1.
💯 2
n
Additionally, you can write a delete/create/edit blocking script for all but admins once, then reuse it for any custom record on any account.