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
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 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.
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
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
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.
An object returned from the getInputData function of a Map/Reduce script must be capable of being transformed into what format?
Key/Value pairs
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
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
What can we do to minimise the risk of duplicates being created if a map/reduce fails because of a server disruption?
Set the retryCount and exitOnError options in the script.
Check the context.isRestarted property in each entry point of the sccript then handle if true.
System Response After a Map/Reduce Interruption
Give an example of logic that we can use to avoid duplicates if a map/reduce fails because of a server disruption & the context.isRestarted property returned true?
Create a flag checkbox on records that will be processed via a map/reduce, so we can check if this record is already processed or not.
Ensure this checkbox flag is checked once processed.
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.
How long ideally should a map/reduce or scheduled script be designed to run?
No more than 5 minutes, if possible.
Optimizing SuiteScript Performance
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.
We should create twice as many non-scheduled deployments as the total number of simultaneous calls you anticipate for a scheduled script.
I don’t know why.