Showing Standard NetSuite Messages in the “View” Mode

It is not possible to show any standard NetSuite messages from a Client Script in view mode since the scriptContext.mode parameter of the pageInit(scriptContext) function does not support such a value as view.

It is also not possible to achieve this in User Event Script beforeLoad(scriptContext) function as well since the Message.show() method is not supported there.

However, in some cases it may be handy to provide users with a message (a warning or a hint) when they open a record in view mode. For instance, to notify a user of a record tied to the one being viewed.

There is a workaround which still allows to show standard NetSuite messages from a User Event Script by invoking a Client Script using a String with an appropriate HTML Script tag set as a value of a field on a form.

This can be done by following these steps:

  1. Create a User Event Script.
  2. Create a condition inside the beforeLoad(scriptContext) function to check if the scriptContext.mode is equal to view.
  3. Add a field of the INLINEHTML type to the current form.
  4. Create a String to store a HTML Script tag with the code needed to invoke the message using the N/ui/message module.
  5. Set the defaultValue property of the field to the String

This would allow the execution of methods found in the N/ui/message module when the page is going to be initialized, just like in a Client Script.

Script :

function beforeLoad(scriptContext) {‌
	
	if (scriptContext.mode === scriptContext.type.VIEW) {‌
		                
            var currentForm = scriptContext.form;
                          
            // Sets a String containing an HTML <script> tag which would be executed on page load 
            var html = '<script>';
                html += 'require([\'N/ui/message\'], function (message){‌'; // Loads the N/ui/message module
	                html += 'var onViewMessage = message.create({‌'; // Creates a message
	                html += 'title: \'Pre-invoiced\', '; // Sets message title
	                html += 'message: \'This Sales Order has been pre-invoiced\', '; // Sets the message content
	                html += 'type: message.Type.INFORMATION'; // Sets the type of the message using enum
	                html += '}); ';
                html += 'onViewMessage.show(10000);'; // Sets the amount of time (in ms) to show the message
                html += '})';
            html += '</script>';
           
            // Adds a field with the INLINEHTML type to store the HTML String containing the <script> tag 
            var field = currentForm.addField({‌
            	id: "custpage_alertonview_preinvoice",
            	label: "PRE-INVOICE",
            	type: serverWidget.FieldType.INLINEHTML
            	                	
            });
            
    	field.defaultValue = html;
    	    
	}
}

Leave a comment

Your email address will not be published. Required fields are marked *