In our previous article, New to NetSuite | N/currentRecord Module Overview, we discussed the purpose and usage of the N/currentRecord module.
In this article, we’ll take a closer look at a useful object for script customization: ‘getValue()’
The ‘getValue()’ method retrieves the value of a specific body field from the current record. It’s often used in Client Scripts to perform conditional logic, display alerts, or trigger other automated actions based on field data.
Business Scenarios
- Auto-update currency: Businesses can use ‘getValue()’ to read the subsidiary and auto-set the currency field to match, ensuring transactions use the correct accounting currency automatically.
- Display warning messages: Use ‘getValue()’ to check a customer’s credit status and display alerts before saving an order, minimizing financial risk and approval delays.
- Paired with ‘setValue()’: After retrieving a field value, you can easily update another field using ‘setValue()’, enabling powerful dynamic forms.
Sample Script
/**
* @NApiVersion 2 .x
* @NScriptType ClientScript
*/
define(['N/currentRecord'], function(currentRecord) {
function saveRecord(context) {
var rec = currentRecord.get();
var total = rec.getValue({ fieldId: 'total' });
if (total > 10000) {
alert('Large order! Please confirm approval.');
}
return true;
}
return { saveRecord: saveRecord };
});
- The script displays an alert message when a user tries to save a record with a total amount greater than 10,000.
Notes / Key Takeaways
Always test scripts in a Sandbox before deploying to Production. Replace sample field IDs with those specific to your account configuration.
DISCLAIMER: The sample code described herein is provided on an "as is" basis, without warranty of any kind, to the fullest extent permitted by law. Oracle + NetSuite Inc. does not warrant or guarantee the individual success developers may have in implementing the sample code on their development platforms or in using their own Web server configurations.
Oracle + NetSuite Inc. does not warrant, guarantee, or make any representations regarding the use, results of use, accuracy, timeliness or completeness of any data or information relating to the sample code. Oracle + NetSuite Inc. disclaims all warranties, express or implied, and in particular, disclaims all warranties of merchantability, fitness for a particular purpose, and warranties related to the code, or any service or software related thereto.
Oracle + NetSuite Inc. shall not be liable for any direct, indirect, or consequential damages or costs of any type arising out of any action taken by you or others related to the sample code.
Stay updated by following New to NetSuite > SuiteCloud category to receive notifications whenever new articles are published.