Optimizing Performance in SuiteScript

Avoid loading a record if you don’t need to

Loading a record costs between 2 and 10 units of governance, and saving it costs between 4 and 20. Loading a record also loads metadata about the record, making the process take longer.

If you need to find values on a record, use a search. When creating or loading a search, minimize the columns to only those you need. Filter as much as you possibly can — it is faster to let the database fiddle with the data than for you to do so in your code (e.g., do not load an entire table and then go through the results yourself for a particular value — add a filter).

If you know the ID of the record you’re targeting, use search.lookupFields. It costs 1 unit of governance (compared to the 10 you would have to use to call getRange() or each() on a resultSet), and it’s faster.

If you need to change values on a record, use record.submitFields. It uses between 2 and 10 units of governance and is faster than loading and saving a record.

Set ignoreMandatoryFields to true

Tread with care here: ignoreMandatoryFields is an optional parameter of record.save() that is false by default. You can see a small performance increase by eliminating this data check when saving a record, although it should be used ONLY when the data coming in or out is completely controlled and validated for correctness or integrity by script.

Minimize the calls you make to the database

Grab as much of the data required as you can in the smallest number of queries. Use joins! When updating a record, track the values to be updated in code and do one save/submitFields call at the end of all your logic.

Another way to minimize disk calls is through consolidating scripts. It’s slower to access data in disk than it is to access data in memory, so the more you can get NetSuite to load into memory at once, the better.

Use Map-Reduce scripts

Map-Reduce scripts are insanely powerful — they handle parallel processing and governance management automatically and can be scheduled . Tasks that are a good fit for map-reduce are those that are logically “repetitive” — such as creating new records or updating values on a set of records. If you are thinking of using a Scheduled Script, think about if you can use a Map-Reduce script instead.

Utilize object mappings to minimize iteration

Say you have a list of Customers, and a list of invoices for those customers. A Customer can have more than one invoice, so how do you match them up? You can use a nested for-loop like so:

for(var i = 0; i < customer.length; i++) {
for(var j = 0; j < invoice.length; j++) {
if(invoice[j].customerId == customer[i].id) {
// do something
}
}
}

But this iterates (i*j) times. If there are 100 customers and 500 invoices, that’s 50,000 iterations! Nested for-loops are necessary at times, and they work fine for finite datasets that won’t change significantly, such as a list of states. But for a potentially infinite datasets, such as a list of invoices, they can get unwieldy. Using an object map for this scenario could look like this:

var invoiceMap = {};
for(var i = 0; i < invoice.length; i++) {
var customerId = invoice[i].customerId;
if(!invoiceMap.hasOwnProperty(customerId)) {
invoiceMap[customerId] = [];
}
invoiceMap[customerId].push(invoice[i]);
}
for(var j = 0; j < customer.length; j++) {
var customerInvoices = invoiceMap[customer.id];
// do something
}

Connect the two using the same value you were using in the comparison statement in the nested for-loops. You end up with the same information, but since they’re not nested, there are only (i+j) iterations. If there are 100 customers and 500 invoices, that’s 600 iterations compared to the 50,000 of the nested loop.

Resource: https://medium.com/@heavylion/optimizing-performance-in-suitescript-fe50d7cf1473

Explain about “Inventory Record & Item Types” in NetSuite

Track your items Individually or as group and can also track serial and lot number of you inventory. Includes history of the recent transaction in each inventory item.You can also Track the items individual or group of track the inventory items.

Item record types:

Navigate for Items: Goto > List > Accounting > Items.

new-item-type
  • Inventory item:

Items are selling and service the part of raw materials purchase form vendor. when you buy and sell the item, quantity on hand and when you purchase items and receive.

  • Item Group:

Item groups are used to manage inventory by dividing inventory items into groups based on items. Accounts for sales, purchase, inventory, and production can be set up in detail according to the company’s needs.

  • Kit/Package:

Component items can be inventory, non-inventory, service, assembly, or kit items. Kit or package items are useful for grouping component items together that are sold together.You can assign multiple price levels to your kits and make them available.You can only description and amount of the kit or package.

  • Assembly/Bill of Materials:

Netsuite enable you to track both raw materials and assemble items are track separately. A Bill of Materials can define products as they are ordered,as they are built, or as they are maintained. The different types of Bill of Materials depend on the business need and use for which they are intended.

  • Serialized Inventory Item:

The serial number identifies each individual item. If an inventory item is classified as a serialized item, a serial number must be entered for each item purchased or manufactured.  You first enable serialized inventory items in your Netsuite account before you can access this record type.

Go to Setup > Company > Enable Features. On the Items & Inventory tab, under inventory Select the Serialized inventory Check box.

  • Serialized Assembly:

This often means having enough stock of goods to the inventory totals as well as subtracting the most recent shipments of finished goods to buyers. When properly managed and appropriately stocked a warehouse provides a consistent supply of material when it is needed.

Track the Inventory items and rew materials and finished items track the separately. Inventory items by assigning a serial number to each assembly individually. You can track every items as showing the details.

Resource: https://netsuiteblogs.curiousrubik.com/explain-about-inventory-record-item-types-in-netsuite

Tạo trang giống vầy với WordPress.com
Hãy bắt đầu