If you’re working with NetSuite customisations, you’ve probably wanted to display friendly messages—like reminders, warnings, or confirmations—directly on your record pages. Maybe you’re trying to alert users about an overdue invoice, remind them of a discount policy, or simply acknowledge a status update.
You may have explored the N/ui/message module in SuiteScript, which allows you to display banner-style messages right on the record page. However, there’s one key limitation that can trip you up.
The Problem: Client Scripts Don’t Run in View Mode
Client Scripts in NetSuite are great for running code on the record’s user interface, but they only trigger when the record is being created or edited. That means if a user simply opens a record in View mode, your client script won’t run at all, and the message won’t appear.
This limitation can be frustrating, especially if you’re trying to show helpful information without requiring the user to enter edit mode.
The Solution: Use a User Event Script with beforeLoad
The workaround is elegant and powerful: instead of relying on a Client Script, use a User Event Script—specifically the beforeLoad entry point.
Why? Because User Event Scripts are executed on the server before the record is rendered in the UI, including when the record is viewed. This gives you the perfect opportunity to inject messages, even when users aren’t editing the record.
Here’s a basic example that displays a message only when the record is viewed:
/**
* @NApiVersion 2.1
* @NScriptType UserEventScript
*/
define([‘N/record’, ‘N/ui/message’], (record, message) => {
const beforeLoad = (scriptContext) => {
// Check if the record is being viewed (not edited or created)
if (scriptContext.type === ‘view’) {
// Add a banner message to the record
scriptContext.form.addPageInitMessage({
type: message.Type.CONFIRMATION, // Can also be WARNING, ERROR, etc.
message: ‘This is a message in view mode’,
duration: 7000 // How long the message stays on screen (in milliseconds)
});
}
};
return { beforeLoad };
});
Breaking Down the Code
Let’s walk through what each part of this script does:
- @NApiVersion 2.1: This specifies that we’re using SuiteScript 2.1, the modern API version for NetSuite scripting.
- @NScriptType UserEventScript: This tells NetSuite that the script should run on server-side record events like loading, creating, or editing.
- beforeLoad(scriptContext): This function executes just before the record is loaded into the UI. It’s your chance to modify the form or add messages.
- scriptContext.type === ‘view’: We check whether the user is just viewing the record, not editing or creating it.
- addPageInitMessage: This adds a non-intrusive banner-style message to the top of the record form.
When Should You Use This?
Here are a few common scenarios where this technique is especially useful:
- Highlight important status information: For example, notify users when a sales order is on hold.
- Remind users of key policies: Show a reminder message when viewing a vendor bill or invoice.
- Alert based on custom field values: Display messages based on specific record conditions without cluttering the UI with extra fields.
- Improve user experience: Provide helpful guidance to users without disrupting their workflow.
Pro Tip: Use Message Types Wisely
NetSuite’s N/ui/message module supports multiple message types:
- INFORMATION: Neutral info
- CONFIRMATION: Positive feedback
- WARNING: Attention needed
- ERROR: Critical issue
Use these strategically to guide users without overwhelming them.
Also, because these messages are temporary and disappear after a few seconds, they don’t require extra user interaction, making them ideal for improving usability.
Final Thoughts
This small change—from Client Script to User Event Script—can significantly boost the effectiveness of your NetSuite customisations. If you’ve been frustrated by the inability to show messages in View mode, this technique is your answer.
With just a few lines of code, you can:
✅ Provide key info
✅ Reduce user errors
✅ Create a smoother, smarter NetSuite experience
Need help implementing this or customising your NetSuite environment? Reach out to our team of experts—we’re here to help you get more from your ERP.