Step Two:
– Add the Honeypot field to your online form. Since we’re working with Leads that will live in Setup > Marketing > Online Customer Forms. If you utilize Online Case Forms that will reside in Setup > Support > Online Case Form
– Click the edit button once you choose a form. You’ll see in the select fields section where you’ll be able to find your new Honeypot field.
Step Three:
Add the script. This script will run Before Submit. Meaning after the fields have been filled in but before the record has been saved. It will check to see if the Honeypot field has data filled in and if it does it will prevent the save of the customer record. Each action is explain within the script so you know exactly what each piece does.
The Code
/**
* @NApiVersion 2.1
* @NScriptType UserEventScript
*/
define(['N/record', 'N/error', 'N/log'], (record, error, log) => {
const beforeSubmit = (context) => {
try {
// Log the event type
log.debug('User Event Triggered', `Event Type: ${context.type}`);
// Only run on record creation
if (context.type !== context.UserEventType.CREATE) {
log.debug('Event Skipped', 'Not a CREATE event');
return;
}
// Runs on any new record regardless of type
const newRecord = context.newRecord;
// Log the record type and ID for debugging
log.debug('New Record Details', `Type: ${newRecord.type}, ID: ${newRecord.id}`);
// Check the honeypot field
const honeypot = newRecord.getValue({ fieldId: 'custentity4' });
// Log the honeypot field value
log.debug('Honeypot Field Value', `Value: ${honeypot}`);
// if Honeypot field has a value
if (honeypot) {
// Log spam detection before throwing the error
log.error('Spam Detected', 'The lead was identified as spam.');
// Throw an error that prevents the save
throw error.create({
name: 'SPAM_LEAD_BLOCKED',
message: 'The lead was identified as spam and will not be created.',
notifyOff: true
});
}
} catch (err) {
// Log unexpected errors for debugging
log.error('Error in beforeSubmit', err.message);
throw err; // Re-throw the error to avoid suppressing it
}
};
return {
beforeSubmit
};
});
Step Four:
Deploy the script, test it thoroughly, and check the execution log for any issues.
Conclusion:
Tackling spam leads in NetSuite doesn’t have to be a daunting task. By implementing the Honeypot method, you can keep your online forms free of unwanted submissions without the need for Google reCAPTCHA. This simple yet effective approach combines a hidden field with a user event script to catch and block bots before they clutter your system. Not only does this streamline your lead management process, but it also ensures your team’s focus stays on genuine opportunities. Take control of your NetSuite forms today with this practical solution—your productivity will thank you!