Marty Zigman Marty Zigman
Prolecto Labs Accelerator Templates

Automatically Load Specific NetSuite Forms via SuiteScript

NetSuite Technical



This article is relevant if you need a mechanism to force users to a specific NetSuite form definition.

Background

NetSuite form management utilizes user roles to decide the “preferred” or “restricted” form as a method to control logic for what form is used in viewing and editing records. Generally, these administrative preference options work very well. Yet, there are times when we need to be more assertive.

A client had a requirement to dynamically present information depending on the role.  Thus, the concept of defining multiple forms to partition logic starts to draw trade-offs — when you have many forms, subsequent logic updates become cumbersome to propagate across forms. The scripted dynamic approach gives designers more control and a centralized location to assess logic.

Sometimes, we just need to ensure that a specific form loads for users — and we can’t express it well in the point-and-click form customization. In the spirit of scripted logic, we can force a particular form load for users based on our own criteria. The script pattern takes advantage of the redirect function evaluated as the form is loading.  This means that the wrong form never arrives in the user’s browser — instead, logic on the server redirects the browser to load the correct form based on the CF URL parameter. The user never sees the logic unfold.

Readers may want to see my 2021 article, Tip: Learn How to Load NetSuite Custom and Standard Forms via URL, to gain more background on how the form IDs work.

NetSuite Server Side SuiteScript (2.1) to Automatically Redirect and Load Form

The following script illustrates the general pattern to redirect to a specific form. In the pattern below, the logic is hard coded for customer records to load form 108; naturally, any logic needed can be intelligently adapted for your specific use case.

const beforeLoad = (scriptContext) => {
	var logTitle = "beforeLoad " + 
		scriptContext.type + " " + 
		scriptContext.newRecord.type + " " + 
		scriptContext.newRecord.id + " via " + 
		JSON.stringify(runtime.executionContext);

	try {
		var custForm = scriptContext.request.parameters.cf;
		log.debug(logTitle,'custForm: '+custForm);

		//use table, deployment parameter or other method for holding form IDs
		if (custForm != 108) {
			log.debug(logTitle,'form is ' + custForm + ', redirecting to 108');
			redirect.toRecord({
				type: record.Type.CUSTOMER,
				id: scriptContext.newRecord.id,
				parameters: {'cf':'108'},
				isEditMode: scriptContext.type == 'edit' ? true : false
			});
		}
	}
	catch(e) {
		var errStr = '';
		if(typeof(e) == 'object'){
			errStr = e.name + ', ' + e.message;
		}
		else errStr = e;
		log.error(logTitle,'error: ' + errStr);
	}
}

NetSuite Scripted Platform Leadership

I would like to thank Matthew M., Senior Technical Analyst, in our firm, for enthusiastically bringing forth this capacity. The logic above is a simplified version of the client-presented challenges we face daily in our NetSuite Systems Integration Practice.

While our philosophy is to have business purpose lead the need for action and then use every built-in feature to address our client requirements, we frequently need to take matters into our own hands and use the platform for scripting our way into the future. Our clients appreciate that we can say ‘Yes!’ to their demands — yet we have conversations about the implications of their technical choices so they can, with our support, responsibly maintain their unique NetSuite account configuration.

If you found this article relevant, feel free to sign up for notifications to new articles as I post them. Perhaps you hold similar values as we do and seek to be appreciated for the unique way you see the world.  If so, let’s have a conversation.

Marty Zigman

Holding all three official certifications, Marty is regarded as the top NetSuite expert and leads a team of senior professionals at Prolecto Resources, Inc. He is a former Deloitte & Touche CPA and has held CTO roles. For over 30 years, Marty has produced leadership in ERP, CRM and eCommerce business systems. Contact Marty to set up a conversation.

More Posts - Website - Twitter - Facebook - LinkedIn - YouTube

About Marty Zigman

Marty Zigman

Holding all three official certifications, Marty is regarded as the top NetSuite expert and leads a team of senior professionals at Prolecto Resources, Inc. He is a former Deloitte & Touche CPA and has held CTO roles. For over 30 years, Marty has produced leadership in ERP, CRM and eCommerce business systems. Contact Marty to set up a conversation.

Biography • Website • X (Twitter) • Facebook • LinkedIn • YouTube

Leave a Reply

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