The quick answer
Use context.form.addPageInitMessage() in a User Event beforeLoad handler. The server can calculate a value and include it directly in the initial message. A separate Client Script or inline-script bootstrap is unnecessary for this requirement.
Before you start
This walkthrough uses a synthetic local exercise: its Code Editor, form/record API stubs and bounded Sales Order model do not demonstrate an account deployment or production execution. The saved JavaScript runs against those stubs; the order page uses a limited source-derived projection.
SO-9473 for Maple Industrial Services has two service rows, amounts 45.00 and 65.00, total 110.00. The prepared source, order_review.js, already imports N/ui/message, exports beforeLoad and guards context.UserEventType.VIEW. Its warning text is initially static.
The current Oracle N/ui/message sample supplies a styling reference only. Account/form appearance can differ. The separate Form.addPageInitMessage API documentation establishes support for beforeLoad and interactive View/Create/Edit contexts; the example deliberately selects View.
01 · Inspect the warning and source
In the local exercise, open SO-9473. Its Order review banner says Review this order before fulfillment. It is a notification, so it changes no fields or approval status.
Open order_review.js in the local Code Editor. The handler gets the item-row count with:
const itemCount =
context.newRecord.getLineCount({
sublistId: 'item'
});
This counts sublist rows, including service rows. It does not sum Quantity or count units. The local order model has two rows.
02 · Include the row count
Change only the message property to include itemCount. Written across lines for readability, the same expression is:
message:
'Review ' + itemCount +
' order lines before fulfillment.',
Keep message.Type.WARNING, the title Order review, duration: 0 and the VIEW guard. The value here is fixed text plus a server-derived number; do not generalize that concatenation to arbitrary user-controlled HTML or executable JavaScript.
Click Save, then Run local exercise. The harness executes the saved source against its form/record stand-ins. It reports Item line count: 2, Queued page messages: 1, and Review 2 order lines before fulfillment. Enlarge to inspect the complete output and saved-source status.
03 · Verify the View warning
Return to the same local order in View mode. Its source-derived banner now includes the count:
SO-9473, Maple Industrial Services and Total 110.00 remain. The User Event adds the message during beforeLoad. The API documentation says it is displayed after client pageInit processing completes; it does not implement a Client Script pageInit handler. duration: 0 means no timed expiry. Each qualifying page load adds a new message rather than persisting this banner as record data.
04 · Check Edit and return
Click Edit in the local order. No banner appears because the handler explicitly returns unless the event is VIEW. The API can also be used for create/edit when the User Event permits those contexts; the absence here comes from this source guard.
Click Cancel. The same View page displays its count-based warning again:
Open Items. Inspection Service and Repair Service remain at Quantity 1 each, with amounts 45.00 and 65.00, total 110.00. Enlarge the screenshot to inspect the columns together. The exercise ends here; no transaction is saved or fulfilled.
The warning is advisory. Enforcement would require a separate validation or server-side control and appropriate account testing.
Common questions
Do I need a Client Script to show server-calculated data in an initial warning?
Not for this requirement. beforeLoad already has the server value and the form. Call form.addPageInitMessage directly. Later browser interaction that needs structured server data is a separate transport problem; this example does not implement a hidden-field bridge.
Why does the banner disappear in Edit mode?
This handler guards context.UserEventType.VIEW. That explicit condition omits the message in Edit. A Client Script pageInit does not run when a record is merely viewed; this form-message API is a different mechanism.
Does getLineCount return total item quantity?
No. It counts item-sublist rows. These two service rows each happen to have Quantity 1, but a row with Quantity 10 still counts as one row.
Can N/cache pass the value to a Client Script instead?
N/cache is server-side and is not available as a Client Script messaging module. For an initial message, the direct beforeLoad form API removes the need for that bridge.
Does the warning prevent saving or fulfillment?
No. It displays a notification, without validating, blocking or persisting fields in this example. A real account needs a valid script deployment, applicable audience/record context and observed testing; the successful local harness does not establish those results.