Custom forms can help guide users during data entry, but some fields need extra control to prevent incomplete or incorrect records. In many cases, required fields are enough. In other cases, client validation can help check values before the record is saved.
Using both carefully can make data entry safer without making the form too difficult to use.
Scenario
A business team uses a custom form to capture request information.
The form includes important fields such as:
- Request Type
- Requested Date
- Priority
- Approval Reason
- Contact Email
Some fields should always be completed, while others need validation only when certain conditions are met.
For example, if Priority is set to High, the user must enter an Approval Reason before saving.
Solution
Use required fields for information that must always be entered.
Use client validation when the rule depends on user input or a specific condition.
This allows the form to stay controlled while still supporting flexible business logic.
Required Fields vs Client Validation
Use required fields when the value is always needed.
Examples:
- Request Type
- Requested Date
- Customer
- Department
Use client validation when the requirement depends on a condition.
Examples:
- Require Approval Reason only when Priority is High
- Require Follow-Up Date only when Status is Pending
- Validate email format before save
- Warn users when a date is earlier than today
Sample Client Script
The sample below checks whether Priority is set to High. If it is, the script requires the Approval Reason field before the user can save the record.
Replace the field IDs with the actual field IDs from your NetSuite account before testing.
/**
*@NApiVersion 2.1
*@NScriptType ClientScript
*/
define([], () => {
function saveRecord(context) {
const currentRecord = context.currentRecord;
const priority = currentRecord.getText({
fieldId: 'custrecord_request_priority'
});
const approvalReason = currentRecord.getValue({
fieldId: 'custrecord_approval_reason'
});
if (priority === 'High' && !approvalReason) {
alert('Approval Reason is required when Priority is High.');
return false;
}
return true;
}
return {
saveRecord
};
});
Simple Code Breakdown
This is a Client Script.
It runs when the user clicks Save on the record.
What the script does
The script checks two fields:
If Priority = High and Approval Reason is blank, the script stops the record from saving.
Main parts
const currentRecord = context.currentRecord;
Gets the record the user is currently editing.
const priority = currentRecord.getText({
fieldId: 'custrecord_request_priority'
});
Gets the selected Priority value.
Example:
High
const approvalReason = currentRecord.getValue({
fieldId: 'custrecord_approval_reason'
});
Gets the value entered in the Approval Reason field.
if (priority === 'High' && !approvalReason) {
Checks if:
- Priority is High
- Approval Reason is empty
alert('Approval Reason is required when Priority is High.');
return false;
Shows a message and prevents the record from saving.
return true;
Allows the record to save when the rule is satisfied.
Summary
This script makes Approval Reason required only when Priority is High.
Where to Deploy
Deploy the Client Script on the record or form where users enter the data.
Example:
- Custom Record form
- Customer form
- Vendor form
- Transaction form, depending on the use case
The script should be tested on the same form and role that users will use.
Notes
- Use required fields for simple always-required values.
- Use client validation for conditional rules.
- Keep validation messages clear and specific.
- Avoid too many pop-up validations because they can frustrate users.
- Test in sandbox before deploying to production.
- Confirm the script works for the intended roles and forms.
- Client validation helps guide users, but server-side validation may still be needed for stronger enforcement.
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.
Share your insights and experiences in the NetSuite Admin Corner.