Pages

2013/09/23

Overcoming Metering Limitations

“Nobody ever did, or ever will, escape the consequences of his choices.”
Alfred A. Montapert


NetSuite is just like the real world, each action has its cost and its consequences. Understandably, NetSuite has put a cost on each call made to its database. The different actions taken towards the database have a varying unit cost. Each script has its own metering limit. When this limit is exceeded, the script stops working. It is of the utmost importance to take into consideration the potential total metering unit cost of your scripts in order to prevent any negative consequences. The following blog post will give you a set of tools to overcome metering limitations.


One common scenario you will come across while scripting is accessing values of a customer or item linked to a transaction record. So what should you do to access these values? Should you use nlapiLookupField? Should you use nlapiLoadRecord? You could. But each of these calls has a cost. Each time you use the calls above the units used start to pile up, and then, boom goes the dynamite and your script stops working. As the size of the company using NetSuite grows larger and larger it is becoming less and less uncommon to see transactions with over 100 line items (I have seen transactions with over a thousand line items) and this increases the significance of each metering unit used.


To overcome the above limitations and ensure no negative consequences, one solution is to use sourced fields. Using sourced fields will let you access the values directly without any associated unit cost. Below will be two examples. One sourcing through a body field and one through a column field.


Example 1 : Category from customer



Scenario : We need to automatically apply a specific discount item on a sales order when a customer’s category is ‘Corporate’. We therefore need to create a transaction body field sourced from the customer’s category. We wish to display this information to the end user but he shouldn’t be able to modify the value.

Solution : Create a new transaction body field. Type : List/Record. List/Record : Customer Category. Store value : False. Applies to : Sale. Display type : Inline Text. Subtab : Main. Source List : Customer. Source From : Category.


Result : You can now access the ‘category’ value directly. Using nlapiGetFieldValue(‘custbody_cust_category_sourced’) will work and will not cost any unit.



Example 2 : Offer support from item


Scenario : A case is automatically created for each item that needs support on creation of a sales order. The ‘Offer Support’ value must not be visible to the end user.


Solution : Create a transaction column field sourced from the Item’s Offer Support. Type : Checkbox. Store Value : False. Applies To : Sale Item. Display Type : Normal. Source List : Item. Source From : Offer Support.


Now, to hide the field but keep the value persistent you need to Save & Apply To Forms, leave Show checked but blank out the label (as seen below) :



Result : Field is correctly hidden from the line item but the value is accessible with not unit cost.



With these tips in hand you will have more control over the consequences of your API calls to the database and will be one step closer to a NetSuite world without metering limitations.


References :




Scripts unit limits :

No comments:

Post a Comment