Automatically Load Specific NetSuite Forms via SuiteScript

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.

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);
	}
}

Leave a comment

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