SuiteScript Best Practices Flashcards
When searching for a small amount of fields what module & function should we use instead of loading the record?
nSearch.lookupFields, instead of nRecord.load
When building a custom UI for Suitelets outside of the NetSuite UI, which API’s should we use to help users manage their credentials within the custom UI?
The N/auth Module and N/crypto Module
Suitelets and UI Object Best Practices
If using a search in the getInputData function of a Map/Reduce, what should we return and why?
We should return the nSearch.search object or a reference to the search, instead of the results.
This is because running the search and returning the results has a higher chance of the search timing out.
Map/Reduce Script Best Practices
For a map/reduce script, which 2 entry functions must be kept relatively lightweight?
The map and the reduce entry points, because their governance is limited more than the getInputData or summarize functions.
How can you configure a require Object?
You can configure a require Object by associating a script to a JSON-formatted configuration file using the @NAmdConfig JSDoc tag within your script.
How long ideally should a map/reduce or scheduled script be designed to run?
No more than 5 minutes, if possible.
Optimizing SuiteScript Performance
What setting option for suitelets should be used only when absolutely necessary?
Available without login
Why should we not change the buffer size field on a map/reduce script?
Because although this can increase the available processing time, but it has a higher chance to cause data duplication or loss.
For client scripts, what happens when using the Advanced Employee Permissions feature?
The search columns available to the user is dependent on the permissions assigned to their role.
You can use the JSDoc tag @NModuleScope to limit the access that other scripts have to this module. What are the scopes you can set with this tag?
SameAccount
Limits script access to modules native to the same environment in which the script was created and uploaded.
This environment includes the account from which a bundle is installed and can also include the related family of sandbox accounts. For more information about sandbox accounts, see Understanding NetSuite Account Types.
A script file that is ‘native’ to the environment is added to an account using an authenticated user session.
Access disallowed when:
A bundled module from a different source account attempts to import the module.
Visibility of Source Code:
Visible during runtime
Examples:
Installing a customization from a single sandbox to a production environment that is linked to the same account.
Distributing a bundle with private business logic as an ISV (Independent Software Vendor).
TargetAccount
Limits script access to modules native to the same source or target environment as the script.
A source environment includes the NetSuite account (and any associated sandboxes and Release Preview accounts) from which a bundle is installed into another account.
A target environment includes the NetSuite account (and any associated sandboxes and Release Preview accounts) into which a bundle is installed (whether using Bundle Copy or Bundle Install).
Access disallowed when:
A bundled module that is not native to the target or source account attempts to import the module.
Visibility of source code:
Hidden during runtime
Examples:
Account administrators distributing private business logic between accounts they control, and the modules in the bundle are needed by other modules created in the target account
Distributing a bundle with public APIs intended for import only by modules native to the target account.
Public
Any bundle (native and third party) that is installed in the account can run the script.
Access disallowed when:
The script is not installed in the account.
Visibility of source code:
Hidden during runtime
Examples:
Customers installing customizations from multiple sandbox accounts to production, where modules from different sandboxes need to load each other.
Installing a customization from a development account to a sandbox or production account.
Developing open source code
How long should suitelets optimally take at most to run?
10 seconds or under
Optimizing SuiteScript Performance
True or False
We should aim to minimise API calls that perform Load, Search, or Save record operations.
True.
We should avoid saving multiple records in an After Submit function, and avoid loading and submitting a record in a Before Submit function.
True or False: We should create twice as many non-scheduled deployments as the total number of simultaneous calls you anticipate for a scheduled script.
True
Does a custom module require JSDoc tags?
A custom module script is not required to have JSDoc tags, but you should use them. The following illustration shows this sample’s JSDoc block.
Consider the time zone your scripts must use. Which time zone will server side scripts use by default?
Server side scripts will use the time zone specified in your NetSuite account.
If necessary, be sure to convert your time zones before using them.
For a map/reduce script what are the governance limits for each entry point?
getInputData: 10,000
map: 1,000
reduce: 5,000
summarize: 10,000
Map/Reduce Governance
A map/reduce script can be interrupted at any point by an application server disruption. Afterwards the script is restarted. What could this lead to?
Duplicate data
Why should we schedule Scheduled Scripts to run between 2AM and 6AM PST?
This is the period of time that database activity will be at its lowest. Therefore scripts scheduled between 2AM and 6AM PST will run quicker.
What module should we use instead of N/search when searching for large data sets?
We should use N/task to search for larger data sets.
We should avoid loading and submitting records in what entry point?
Any Before Record Submit entry point.
If using the Advanced Employee Permissions feature on a client script, how should we check if the role has access to that field before setting/getting data?
We should use .getFields().includes([FIELD ID]) to check if the role has access.
Client Script Best Practices
Rather than trying to execute a user event script from another user event script, what should we do?
Create a custom module containing common code between the two user events, and use the module across both scripts.
Regarding sensitive field values, what should we make sure not to do when developing user event scripts?
We should make sure the UE does not read a sensitive field value
User Event Script Best Practices
We should avoid saving MULTIPLE records in what entry point?
Any After Record Submit entry point