2

I have a suitelet which displays a form created with N/ui/serverWidget, and I'd like to display a message at the top of the form. However, all of the N/ui/message documentation says that it is for client-side scripting only. Is there a way to display such a banner without building a separate client script just to do it?

1 Answer 1

6

Yes, use the Form.addPageInitMessage() function. It allows you to pass in either a Message or the same options as message.create(), and will display it when the form loads.

Here's a complete example:

/**
 * Example of how to use Form.addPageInitMessage() to display a notice
 * on a server-rendered form.
 * @NApiVersion 2.x
 * @NScriptType Suitelet
 */
define(['N/ui/serverWidget', 'N/message'], function(ui, message) {
    function onRequest(context) {
        var form = ui.createForm({
            title: 'Example Form',
        });
        form.addSubmitButton({label: 'Submit'});
        form.addField({
            id: 'input',
            type: ui.FieldType.TEXT,
            label: 'Input',
        });
        form.addPageInitMessage({
            type: message.Type.INFORMATION,
            title: 'Message!',
            message: 'A wild message appears!',
        });
        context.response.writePage(form);
    }

    return {
        onRequest: onRequest,
    };
});
2
  • Did you answer your own question? lol, what if you want to show it after the form is loaded? Dec 14, 2022 at 13:56
  • I certainly did. I’d recommend posting your question separately; it’s been a while since I did any NS development and you’ll get more eyes than just mine that way. (But TBH I'm not sure I understand the premise of your question: once the form is loaded, the server script has finished running. The only way to change the form once the client has it is with a client script.)
    – Wolfgang
    Dec 19, 2022 at 1:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.